snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub EeportData()
On Error Resume Next
Dim sFolderPath As String
Dim oFSO As Object
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim wb2 As Workbook
Dim Path As String
Dim FName As String
sFolderPath = "C:\" & Range("O2")
'sFolderPath = "C:\PD\"
MkDir sFolderPath
Set wb1 = ThisWorkbook
Set ws1 = wb1.Sheets("Exp")
Path = sFolderPath
'Path = "C:\PD\"
FName = ws1.Range("M2") & ".xlsx"
ws1.Range("A:G").Copy
Set wb2 = Workbooks.Add
With wb2.ActiveSheet.Range("A:G")
.PasteSpecial (xlValues)
.PasteSpecial (xlFormats)
End With
Application.DisplayAlerts = False
wb2.SaveAs filename:=Path & FName
Application.DisplayAlerts = True
wb2.Close
End Sub
You do not have the required permissions to view the files attached to this post.
Sub Daily_Report()
Dim sFolderPath As String
' Dim oFSO As Object
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim wb2 As Workbook
Dim Path As String
Dim FName As String
On Error Resume Next
sFolderPath = "C:\" & Range("O2").Value
'sFolderPath = "C:\PD\"
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
Set wb1 = ThisWorkbook
Set ws1 = wb1.Sheets("Exp")
' Path = sFolderPath
'Path = "C:\PD\"
FName = ws1.Range("M2") & ".xlsx"
ws1.Range("A:G").Copy
Set wb2 = Workbooks.Add
With wb2.ActiveSheet.Range("A:G")
.PasteSpecial (xlValues)
.PasteSpecial (xlFormats)
End With
Application.DisplayAlerts = False
wb2.SaveAs Filename:=sFolderPath & "\" & FName
Application.DisplayAlerts = True
wb2.Close
End Sub
เซลล์ M2 ต้องมีค่าด้วย Code ถึงจะทำงานได้ กรณีเป็น M2 จากชีตอื่นที่ไม่ใช่ชีต Main จะต้องเขียนระบุชื่อชีตประกอบเข้าไปด้วย Code ด้านบนนี้ค่าใน O2 และ M2 จะนำมาจากชีต Main ครับ