Bentley001
New Member
- Joined
- May 12, 2015
- Messages
- 16
I'm trying to run the code below to copy updated data from another file but am getting a 'Subscript out of Range' error on the line where it is referencing the tab on the source file (Sheets("Source File Tab").Select). The code runs fine when attached to a macro driven button. Confused on why it's not working?
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Application.CutCopyMode = False
Application.DisplayAlerts = False
ThisWorkbook.Activate
Sheets(4).Select
Sheets(4).Cells.ClearContents
Workbooks.Open Filename:="Path to Source File.xls", ReadOnly:=True
Workbooks("Source File Name.xls").Activate
Sheets("Source File Tab").Select
[a1].CurrentRegion.Copy
ThisWorkbook.Activate
[D1].PasteSpecial Paste:=xlPasteValues
[a1].Select
Workbooks("Source File Name.xls").Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Sheets("Sheet1").Select
End Sub
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Application.CutCopyMode = False
Application.DisplayAlerts = False
ThisWorkbook.Activate
Sheets(4).Select
Sheets(4).Cells.ClearContents
Workbooks.Open Filename:="Path to Source File.xls", ReadOnly:=True
Workbooks("Source File Name.xls").Activate
Sheets("Source File Tab").Select
[a1].CurrentRegion.Copy
ThisWorkbook.Activate
[D1].PasteSpecial Paste:=xlPasteValues
[a1].Select
Workbooks("Source File Name.xls").Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Sheets("Sheet1").Select
End Sub