Hi all,
I'm needing some help on this macro I've been developing for a template. The purpose of the macro is to:
I'm having trouble with this line:
It's saying that it couldn't find it with the runtime error '1004'. I know that my issue is turning this string into a workbook so that it will actually open whatever file the user opens.
Any help is appreciated. Thanks guys!
I'm needing some help on this macro I've been developing for a template. The purpose of the macro is to:
- Let the user choose a file to extract data from
- Open workbook (if necessary)
- Copy the data range
- Paste data range
- Close workbook (if necessary)
VBA Code:
' GG Macro()
' To select report to upload for GG sheet for Section
'Setup your 2 workbooks
Set masterBook = ActiveWorkbook
With otherbook = Application.GetOpenFilename(Title:="Choose file", MultiSelect:=False)
End With
If Filename <> False Then
' User pressed Cancel
MsgBox "Please select a file"
End If
'Setup Range from 70.5 or 72 file and copy
Set otherBook2 = Workbooks.Open(otherbook)
Sheets("Paste and Import").Select
ActiveWindow.ScrollColumn = 2
Range("W2:AA67").Select
Selection.Copy
'PasteSpecial to paste values, formulas, formats, etc.
masterBook.Activate
Sheets("Dist List 1").Select
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=48
Call CloseWorkbook
End Sub
Sub CloseWorkbook()
'Close a workbook
otherBook2.Close SaveChanges:=False
End Sub
I'm having trouble with this line:
VBA Code:
Set otherBook2 = Workbooks.Open(otherbook)
It's saying that it couldn't find it with the runtime error '1004'. I know that my issue is turning this string into a workbook so that it will actually open whatever file the user opens.
Any help is appreciated. Thanks guys!