private sub worksheet_open

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
774
Office Version
  1. 365
Platform
  1. Windows
Hi
I'm have a brain freeze or a senor moment
I have a workbook with one sheet in it.
When I open the workbook, I want a macro (opene) to trigger
I put this in sheet1 and nothing (
VBA Code:
Private Sub WorkSHEET_open()
opene
End Sub
I tried to change open to activate and still nothing
I used F8 to make sure the macro works
I tried to put
private sub workbook_ open, then _activate in "this workbook" and still nothing leaving the code in the sheet1

mike


I
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
It should be in 'ThisWorkbook' and it's 'Workbook _open' not 'WorkSheet_Open'
VBA Code:
Private Sub Workbook_Open()
opene
End Sub
If that doesn't work then check that Application.EnableEvents is set to True.
 
Upvote 0
Hi Jasonb75
Hope you and you loved ones are well
Yep, that did it
so....with only only one sheet in the book it goes into "this workbook"
if I have more than one sheet and i want each sheet to open with a macro, then I use worksheet_activate in each sheet, correct?
and if I want to have a certain sheet open when i open the workbook I use
VBA Code:
Sub workbook_activate()
Sheets("Plan").Select
opene
End Sub
I have a hard time remembering which one to use>>> open or activate
"don't ever get old!!!!!!!!!!

mike
 
Upvote 0
Without setting up a test, I can't remember if worksheet activate will work when there is only one sheet. If you tried it and it didn't work then I would say that it is fair to assume no.

In which case, for multiple sheets, I would suggest Workbook_Open in the workbook module and Worksheet_Activate in each sheet module.

However, if you are running exactly the same code on every sheet in the workbook then you could use Workbook_Open and Workbook_SheetActivate in the Workbook module.

Little tip if you forget the correct names for these procedures, there are 2 dropdowns at the top if the code editor. If you click the (General) dropdown, then choose Workbook or Worksheet as appropriate, the second dropdown will give you a list of all valid procedure names, with the mandatory declarations already filled in.
 
Upvote 0
Thanks again Jasonb75
I copied and pasted what you said to a worksheet
Now if I can remember where I put it the next time I need it..............


mike
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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