ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to run VBA macro when the workbook is open? (https://www.excelbanter.com/excel-programming/271122-how-run-vba-macro-when-workbook-open.html)

Ji Wenke

How to run VBA macro when the workbook is open?
 
Hi
I write a Macro in VBA IDE module 1 as:

sub Selection()
xxxxxxx
end sub

If I want EXCEL to run it when this workbook is open,how
can I do that by VBA for that ?(Any sample code available?)


Thanks!

BRs
Ji

Vasant Nanavati[_2_]

How to run VBA macro when the workbook is open?
 
Hi:

Put the following macro in the ThisWorkbook code module:

Private Sub Workbook_Open()
Call Selection
End Sub

I would suggest calling the macro something other than "Selection", though.
Never use reserved words as names!

Regards,

Vasant.




"Ji Wenke" wrote in message
...
Hi
I write a Macro in VBA IDE module 1 as:

sub Selection()
xxxxxxx
end sub

If I want EXCEL to run it when this workbook is open,how
can I do that by VBA for that ?(Any sample code available?)


Thanks!

BRs
Ji





All times are GMT +1. The time now is 05:30 PM.

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