snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub GetSheets()
' Collect Sheets by browse folder directory
Dim Get_Path As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Application.FileDialog(msoFileDialogFilePicker)
Clicked = .Show
If Clicked = 0 Then 'The Cancel button or the X is clicked.
Exit Sub
ElseIf Clicked <> 0 Then ' if OK is pressed
Get_Path = .SelectedItems(1) & "\"
End If
Path = Get_File
End With
Filename = Dir(Path & "*.xlsx")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
You do not have the required permissions to view the files attached to this post.
Sub GetSheets()
' Collect Sheets by browse folder directory
Dim Get_Path As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' With Application.FileDialog(msoFileDialogFilePicker)
' Clicked = .Show
' If Clicked = 0 Then 'The Cancel button or the X is clicked.
' Exit Sub
' ElseIf Clicked <> 0 Then ' if OK is pressed
' Get_Path = .SelectedItems(1) & "\"
' End If
'Path = Get_File
'End With
'Filename = Dir(Path & "*.xlsx")
'Do While Filename <> ""
Get_Path = Application.GetOpenFilename("Excel file(*.xls*),*.xls*")
If Get_Path = "False" Then Exit Sub
Workbooks.Open Filename:=Get_Path, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(VBA.Split(Get_Path, "\")(UBound(VBA.Split(Get_Path, "\")))).Close
'Filename = Dir()
'Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub GetSheets()
' Collect Sheets by browse folder directory
Dim Get_Path As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' With Application.FileDialog(msoFileDialogFilePicker)
' Clicked = .Show
' If Clicked = 0 Then 'The Cancel button or the X is clicked.
' Exit Sub
' ElseIf Clicked <> 0 Then ' if OK is pressed
' Get_Path = .SelectedItems(1) & "\"
' End If
'Path = Get_File
'End With
'Filename = Dir(Path & "*.xlsx")
'Do While Filename <> ""
Get_Path = Application.GetOpenFilename("Excel file(*.xls*),*.xls*")
If Get_Path = "False" Then Exit Sub
Workbooks.Open Filename:=Get_Path, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(VBA.Split(Get_Path, "\")(UBound(VBA.Split(Get_Path, "\")))).Close
'Filename = Dir()
'Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub