I'm trying to take data from one workbook and paste it into another.
The workbooks change every month. I'd like to select the source file using Application.fileDialog.
Sub CopyTest ()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1
'Show the dialog box
.Show
'Store in fullpath variable
fullpath = .SelectedItems.Item(1)
End With
Dim sourceBook As Workbook
Set sourceBook = Application.Workbooks.Open(sourceBookPath)
Dim sourceSheet As Worksheet
Set sourceSheet = sourceBook.Worksheets("Account Detail GHOA ")
Dim targetBook As Workbook
Set targetBook = Application.Workbooks.Open(targetBookPath)
Dim targetSheet As Worksheet
Set targetSheet = targetBook.Worksheets(“Macro Data”)
sourceSheet.Range("A1:W79").Copy targetSheet.Range("A1:W79")
End Sub
I referenced this question to find the above partial solution: Excel VBA file name changes