Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to run on fileopen for all workbooks

Iam creating a macro in VBA. I want this macro to run whenever Iopen
file in excel or whenever i create a new file in excel. How do i d
this ?

In word, I can achieve the above by creating the macro in Normal.do
template file.

How do I achieve this in Excel...how do i make the same macro availab
to all existing and new files in Exce

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro to run on fileopen for all workbooks

Aarti,

This is a bit more complex, but can be achieved with application events

Firstly, all of this code goes in a designated workbook, one that you will
open when you start Excel.

'========================================
In a standard code module, declare a public variable of thisWB

Public thisWB as Workbook

'========================================
Insert a class module, rename it to 'clsAppEvents', with this code

Option Explicit

Public WithEvents App As Application

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)

'your code or a call to your macro

End Sub
'========================================
In ThisWorkbook code module, add this event code

Dim AppClass As New clsAppEvents

Private Sub Workbook_Open()

Set AppClass.App = Application

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"aarti " wrote in message
...
Iam creating a macro in VBA. I want this macro to run whenever Iopen a
file in excel or whenever i create a new file in excel. How do i do
this ?

In word, I can achieve the above by creating the macro in Normal.dot
template file.

How do I achieve this in Excel...how do i make the same macro availabe
to all existing and new files in Excel


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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro available in all workbooks Tigerxxx Excel Discussion (Misc queries) 9 July 23rd 09 03:41 AM
macro help in workbooks equine investor Excel Discussion (Misc queries) 0 March 16th 06 03:18 AM
Using FileOpen Tippy Excel Programming 1 March 4th 04 06:55 PM
Run macro in different workbooks netzig Excel Programming 0 February 10th 04 03:46 PM
Selecting a file path in Excel VBA using FileOpen dialog John Robinson Excel Programming 1 November 1st 03 09:59 AM


All times are GMT +1. The time now is 11:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"