Private sub workbook_open : working but all other excell documents get a global error

TRosseter

New Member
Joined
Jul 26, 2013
Messages
22
vb newbie here, I have a private macro saved in thisworkbook in the .xlsb file, the code works fine if data is in the document but if the cell is blank or has other data when opening up other excel documents I get run-time error '1004': method 'range" of object'_global falied . I can click on end and im in my excel document. I cant figure out how to exclude anything but "history" or "ItemBrowse"
any thoughts would be helpful. I also tried if statements and the same error but will work it the data is in the cell

(my code below)
Code:
Private Sub Workbook_Open()
Select Case Range("a3")
Case "History"
'History_Order_Guide_Without_Pricing2
'code to do something
Case "ItemBrowse"
Order_Guide_With_Pricing2
'code for something else

Case Else
End Select
End Sub
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You should specify the sheet you are referring to:
Code:
Select Case Thisworkbook.sheets("some sheet").Range("a3").Value
 
Upvote 0
revised code im using below:

Private Sub Workbook_Open()
Select Case Range("a3")
Case "History"
History_Order_Guide_Without_Pricing2
'macro name
Case "ItemBrowse"
Order_Guide_With_Pricing2
'macro name
Case Else
End Select
End Sub
 
Upvote 0
just inserted the code posted and now I get run-time error '9': subscript out of range

Private Sub Workbook_Open()
Select Case ThisWorkbook.Sheets("aiiwwaxexcel0").Range("a3").Value
Case "History"
History_Order_Guide_Without_Pricing2
'macro that runs
Case "ItemBrowse"
Order_Guide_With_Pricing2
'macro that runs
Case Else
End Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top