Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Newbie- Excel Startup

Status
Not open for further replies.

HobbitK

Technical User
Joined
Jan 14, 2003
Messages
235
Location
US
Hi everyone...
I am trying to learn VBA and have a simple question..
I want a piece of code to run when the workbook is first opened, like have "sheet2" open and select Range("A4").
It would be similar to VB's Form_Load Event, but I have not been able to figure out where to put that type of code.
Thanks
Michael

 
Use either a sub called
Auto_Open (this goes in a STANDARD module)
or
The Workbook_Open event

Go to VBE and double click on the "Workbook" in your Project viewer
The wb module will be automatically generated
Select "Workbook" from the left side dropdown - the wb_open sub will be automatically generated -just put your code in there Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
xlbo ...
Not working yet ..
I tried your Workbook_Open method.
In the VBE I show a VBAProject with (MyTestProject)
Below is Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(sheet3)
ThisWorkBook 'this has an Excel icon before it
So, I double clicked ThisWorkbook and that brought up
Private Sub Workbook_Open()

End Sub
Inside that procedure I typed
Sheet1.Range("A4").select

I closed the workbook and re-opened it... Cell "A1" is selected. It is not providing valid object names after I type Sheet1.(nothing shows up)
any ideas ... I KNOW it is something I am not doing
Thanks
Michael
 
AnneTroy ..
Thanks I will try that. I am sure it will work. I have been watching and admiring your answers, as well as the site you link to.
Thanks again
Michael
 
Thanks everyone..
at first it did not work, then I set security to LOW and now works great, it was set to High at first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top