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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with vba code 2

Status
Not open for further replies.

jmuscat

Instructor
May 22, 2002
54
AU
I am still a novice with vba, and I have created an excel workbox with macros to automate some functions. Now I would like to add code to the macro, so that when the workbox is opened, it will execute the macro instead of having a macro button on the spreadsheet. Could someone help me with the appropriate code. Many thanks
 
open MS XL, your particular wookbook
press ALT F11
on the left panel, select/2x click the workbook you are in, there should be a 'category' called THIS WORKBOOD, select/2x click this one
in the right / main pane you have your source code screen, at the top it probably says like General / Delarations or somehting of the sort.
On the left, select This Workbook, on the right select your event handlers, in your case WORKBOOK_OPEN
**put your code here**
Everytime this workbook opens, the proceeding code will execute
[yinyang] Tranpkp [pc2]
 
In the VB editor, right-click on the item "ThisWorkbook" of your workbook in the Project window (top left window; you'll probably have to expand the "Microsoft Excel Objects" tree to see the item), and choose "View code". This takes you to the code module of your workbook. From the dropdown box with "(general)", choose "Workbook". This will insert a new sub named "Workbook_Open". In this sub, place a simple call to the macro you want to run when the workbook first opens. That should do it.
Rob
[flowerface]
 
Hey, tranpkp - How come both of us are spending are Sunday night (at the same time, no less) answering VBA questions? ;-)
Rob
[flowerface]
 
Seeing as it is Sunday night for you guys, I have given a star each for the dedication.
JMuscat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top