gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,341
- Office Version
- 365
- Platform
- Windows
I have these two codes that I run on Workbook open. The second runs without any errors. The first one does not.
Note: Sheets("1 Proposal Selection") is visible and not hidden. And the sheet names are different in each workbook.
First
Second
Don't understand why one works and the other does not.
Thanks!
Note: Sheets("1 Proposal Selection") is visible and not hidden. And the sheet names are different in each workbook.
First
Code:
Private Sub Workbook_Open()
'Gets Error message: Run-time error '1004': Application-defined or object-define error
MsgBox "Please be patient while the workbook updates with the latest data from ProPricer"
Sheets("1 Proposal Selection").Activate
Range("B16").Select
With ThisWorkbook
Sheets("1 Proposal Selection").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
End Sub
Second
Code:
Private Sub Workbook_Open()
'code that does not error
Sheets("Step 2").Visible = xlVeryHidden
Sheets("Step 3").Visible = xlVeryHidden
Sheets("DM Parts").Visible = xlVeryHidden
Sheets("DM Assemblies").Visible = xlVeryHidden
Sheets("DM Assembly Elements").Visible = xlVeryHidden
Sheets("Parts").Visible = xlVeryHidden
Sheets("Assemblies").Visible = xlVeryHidden
Sheets("Assembly Elements").Visible = xlVeryHidden
Sheets("Product List").Visible = xlVeryHidden
Sheets("Proposal List").Visible = xlVeryHidden
MsgBox "Please be patient while workbook is updated with ProPricer data."
With ThisWorkbook
Sheets("Proposal List").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
End Sub
Don't understand why one works and the other does not.
Thanks!