EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)Code: Select all
Sub ExpGToTeach()
Dim Wb As Worksheet
Dim myCSVFileName As String
Dim myWB As Workbook
Dim tempWB As Workbook
Dim rngToSave As Range
Dim sFolderPath As String
Dim Path As String
Dim FName As String
' On Error Resume Next
sFolderPath = "C:\" & Range("A17").Value
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
sFolderPath = "C:\" & Range("A17").Value & "\" & Range("A18").Value
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
sFolderPath = "C:\" & Range("A17").Value & "\" & Range("A18").Value & "\" & "Grade"
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error GoTo err
FName = ActiveSheet.Range("A22") & " " & ActiveSheet.Range("A23") & ActiveSheet.Range("A224") & ".csv"
Sheet2.Activate
Set myWB = ThisWorkbook
Set rngToSave = Range("E3:J48")
rngToSave.Copy
Set tempWB = Application.Workbooks.Add(1)
With tempWB
.Sheets(1).Range("A1").PasteSpecial xlPasteValues
Application.DisplayAlerts = False
.SaveAs Filename:=sFolderPath & "\" & FName, FileFormat:=xlCSVUTF8, CreateBackup:=False, local:=True
.Close
Sheet1.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
If MsgBox("ส่งออกไฟล์ชื่อ " & FName & vbCrLf & "ไปไว้ที " & sFolderPath & " เรียบร้อยแล้ว" _
& vbCrLf & "ต้องการเปิด Folder กด Yes ไม่ต้องการ กด No ", 36, "Open Folder") = 6 Then
ActiveWorkbook.FollowHyperlink Address:=sFolderPath, NewWindow:=True
End If
End With
err:
Application.DisplayAlerts = True
Range("E5").Select
End Sub
FileFormat:=xlCSVUTF8
เป็น FileFormat:=xlCSV
ครับ