的設立
兩個工作簿保存在工作簿.XLSM一個文件夾
數據驗證英寸
關閉的.xlsx工作簿,運行代碼之前。該代碼將打開並關閉選定的工作簿。
選擇工作簿,然後單擊按鈕
Sub Button3_Click()
Dim wb As Workbook
Dim ws As Worksheet
Dim lstRw As Long
Dim rng As Range
Dim GetRng As String
Dim MyDir As String
Dim MyFile As String
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
GetRng = ws.Range("A2")
MyDir = "C:\Users\Dave\Downloads\SampleFolder\" 'change folder location"
MyFile = Dir(MyDir & GetRng & "*.xlsx")
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Workbooks.Open (MyFile)
With Worksheets("Sheet1")
lstRw = .Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range(.Cells(2, 1), .Cells(lstRw, 2))
rng.Copy ws.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
ActiveWorkbook.Close True
End With
Application.DisplayAlerts = 1
MyFile = Dir()
End Sub