snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub ExpCsv()
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:\" & "Money"
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
sFolderPath = "C:\" & "Money" & "\" & "Backup"
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error GoTo Err
FName = ActiveSheet.Range("A16").Value & ".csv"
If MsgBox("คุณต้องการส่งออก " & Range("A16").Value & " ใช่หรือไม่ ?", 36, "ยืนยันการส่งออกบันทึกการรับจ่ายเงิน") = 6 Then
Set myWB = ThisWorkbook
Set rngToSave = Range("C3:E14,G3:I14,K3:K14")
rngToSave.Copy
Set tempWB = Application.Workbooks.Add(1)
With tempWB
.Sheets(1).Range("A1").PasteSpecial xlPasteValues
Application.DisplayAlerts = False
.SaveAs Filename:=sFolderPath & "\" & FName, FileFormat:=xlCSV, CreateBackup:=False, local:=True
.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
' MsgBox "ส่งออก" & Range("A18").Value & "ไปไว้ที " & "C:\" & Range("a16").Value & "\" & Range("a17").Value & "\" & "คะแนนสอบ" & "\" & FName
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:
End If
Application.DisplayAlerts = True
Range("A1").Select
End Sub
You do not have the required permissions to view the files attached to this post.