的设立
两个工作簿保存在工作簿.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