How to run VBA macro when the workbook is open?

J

Ji Wenke

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
 
V

Vasant Nanavati

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top