PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Automatically run macro when opening file

 
 
Chris
Guest
Posts: n/a
 
      22nd Dec 2003
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
 
Reply With Quote
 
 
 
 
pikus
Guest
Posts: n/a
 
      22nd Dec 2003
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

 
Reply With Quote
 
 
 
 
Kit
Guest
Posts: n/a
 
      22nd Dec 2003
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
>.
>

 
Reply With Quote
 
chris huber
Guest
Posts: n/a
 
      23rd Dec 2003
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!
 
Reply With Quote
 
Drlegend
Guest
Posts: n/a
 
      23rd Dec 2003
name your macro
auto_open
see example below



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

 
Reply With Quote
 
J.E. McGimpsey
Guest
Posts: n/a
 
      23rd Dec 2003
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 <013401c3c921$b1309240$(E-Mail Removed)>,
"Drlegend" <(E-Mail Removed)> wrote:

> name your macro
> auto_open
> see example below
>
>
>
> sub auto_open
> msgbox("Hello New User")
> end sub
>

 
Reply With Quote
 
New Member
Join Date: Aug 2008
Posts: 1
 
      5th Aug 2008
Quote:
Originally Posted by pikus
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
PIKU >>I had the same question. I did the thing you said, but gives me compile error. It says Sub Expected. I am all new to vba excel project. Please help me out. Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
set a macro to run in word automatically upon opening doc? =?Utf-8?B?Um9i?= Microsoft Word Document Management 1 9th May 2006 04:29 PM
Run macro automatically on opening of worksheet =?Utf-8?B?Ym5rb25l?= Microsoft Excel Worksheet Functions 1 13th Feb 2006 10:46 PM
run a macro automatically upon opening an XLS file??? Ken Soenen Microsoft Excel Programming 2 4th Dec 2005 02:43 AM
MSKSrvr.exe continues to run and run and run after opening Outlook =?Utf-8?B?Zmx5aW5naHVsbHNj?= Microsoft Outlook Discussion 1 22nd May 2005 06:39 PM
Automatically run a macro when opening an Excel file Raphael Saddy Microsoft Excel Programming 10 15th Jan 2004 05:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:24 AM.