ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automatically run macro when opening file (https://www.excelbanter.com/excel-programming/286064-automatically-run-macro-when-opening-file.html)

Chris

Automatically run macro when opening file
 
Hello,
I would like to run a macro automatically when the Excel file opens.
The macro is written, but what do I do from here?

Thank you,
Chris

pikus

Automatically run macro when opening file
 
Open the Workbook.
Press "Alt + F11"
Press "Ctrl + R"
There will be a window labeled Project - VBAProject
Inside that window there will be listed any open workbooks.
Look under the workbook you're working with to find "ThisWorkbook" an
double-click it.
Another window will appear with "ThisWorkbook (CODE)" in the titl
bar.
There will be two drop down menus near the top of this window.
Drop both of these down and select "Workbook" from the one on the lef
and "Open" from the one on the right.
The body of the window should read:

Private Sub Workbook_Open()

End Sub

Place the code there.

- Piku

--
Message posted from http://www.ExcelForum.com


Kit[_2_]

Automatically run macro when opening file
 
Add a SUB procedure titled Auto_Open to your module.
execute your code in that SUB or call your routine as
needed. The next time you open the spreadsheet your code
will automatically run.

Holding down the SHIFT key when opening the spreadsheet
will suppress running the Auto_Open routine for testing.

Sub Auto_Open()

myRoutine

End Sub

Sub myRoutine()

'Do your code here

End Sub

-----Original Message-----
Hello,
I would like to run a macro automatically when the Excel

file opens.
The macro is written, but what do I do from here?

Thank you,
Chris
.


chris huber

Automatically run macro when opening file
 
Pikus-
Thanks! That was the simplest task ever thanks to your detailed
instruction. Much appreciated.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Drlegend

Automatically run macro when opening file
 
name your macro
auto_open
see example below



sub auto_open
msgbox("Hello New User")
end sub


J.E. McGimpsey

Automatically run macro when opening file
 
Note that this method has been deprecated in favor of using the
Workbook_Open event macro, placed in the ThisWorkbook module:

Private Sub Workbook_Open()
MsgBox "Hello New User" 'no parens needed
End Sub

One significant difference: Event macros will run if the workbook is
opened from code. Automacros require an explicit RunAutoMacro
statement.


In article ,
"Drlegend" wrote:

name your macro
auto_open
see example below



sub auto_open
msgbox("Hello New User")
end sub



All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com