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!

execute macro automatically when EXCEL file open 1

Status
Not open for further replies.

chaoma

Technical User
Apr 17, 2005
101
US
Hi,

Does anyone know how to execute a macro automatically when an excel file is opened?

Thank in advance.
 
In the VBE, double click on the workbook.

In the right pane, in the top left box, change (General) to Workbook.

You will see
[blue]Private Sub Workbook_Open()[/blue]
Put your code there.

Of course, the user will still have to enable macros when prompted.

[tt]_____
[blue]-John[/blue][/tt]

Help us help you. Please read FAQ181-2886 before posting.
 
I went to tools, macro, macros...

then create new macro and edit the macro.

However, I cannot change (General) to Workbook because there's nothing else in the dropdown beside (General)?

Thanks.
 
In the VB Editor (VBE), press [Ctrl]+[R] to make sure that you have the Project Browser open. It looks kinda like Windows Explorer and should be on the left side of the screen. It should list all open workbooks. They will look like
VBAProject (Book1.xls)

You are probably currently in Module1, under a folder called Modules. There is another folder called Miscrosoft Excel Objects. Couble click in ThisWorkbook.

Now, follow the directions in my first post.

BTW, for future reference, you can get to the VBE by pressing [Alt]+[F11].

[tt]_____
[blue]-John[/blue][/tt]

Help us help you. Please read FAQ181-2886 before posting.
 
Thank you for your help. A star for you.
 
Glad you got it sorted out
[cheers]

[tt]_____
[blue]-John[/blue][/tt]

Help us help you. Please read FAQ181-2886 before posting.
 
I got another question.

Is there a way to delete or disable the macro so that I can send this excel file to another user so that it won't execute again.

Thank again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top