Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to apply a macro to all workbooks

Whenever I open an excel workbook, or create a new work book, I want
cretain macros to be automatically applied. For example. I want
following workwook open be exceuted to all abobe work books (existing
and new...)"

Private Sub Workbook_Open()

MsgBox "Wecome, welcome..."

End Sub


Is there a way of doing it. I have setup this macro in personal.xlsb
file, but it does not get applied when I create a new workbook or open
an existing workbook. It seems to apply only to personal.xlsb file.


Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default How to apply a macro to all workbooks

There are application events that excel monitors that you can hook into.

Saved from a previous post:

Put this in the personal.xls project's ThisWorkbook module:

Option Explicit
Public WithEvents xlApp As Excel.Application
Private Sub Workbook_Open()
Set xlApp = Application
End Sub
Private Sub Workbook_Close()
Set xlApp = Nothing
End Sub
Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook)

'msgbox "Welcome..."

'this autofit columns if the opening workbook was text
Select Case LCase(Right(Wb.Name, 4))
Case Is = ".txt", ".prn", ".csv"
Wb.Worksheets(1).UsedRange.Columns.AutoFit
End Select
End Sub

Save your personal.xls.
Close excel and reopen it. Your personal.xls workbook show open and set up this
application event.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

You can read more about those application events at Chip Pearson's site:
http://www.cpearson.com/excel/AppEvent.aspx


On 11/26/2011 20:49, zigzagdna wrote:
Whenever I open an excel workbook, or create a new work book, I want
cretain macros to be automatically applied. For example. I want
following workwook open be exceuted to all abobe work books (existing
and new...)"

Private Sub Workbook_Open()

MsgBox "Wecome, welcome..."

End Sub


Is there a way of doing it. I have setup this macro in personal.xlsb
file, but it does not get applied when I create a new workbook or open
an existing workbook. It seems to apply only to personal.xlsb file.


Thanks.


--
Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to apply a macro to all workbooks

On Nov 27, 7:22*am, Dave Peterson wrote:
There are application events that excel monitors that you can hook into.

Saved from a previous post:

Put this in the personal.xls project's ThisWorkbook module:

Option Explicit
Public WithEvents xlApp As Excel.Application
Private Sub Workbook_Open()
* * *Set xlApp = Application
End Sub
Private Sub Workbook_Close()
* * *Set xlApp = Nothing
End Sub
Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook)

* * *'msgbox "Welcome..."

* * *'this autofit columns if the opening workbook was text
* * *Select Case LCase(Right(Wb.Name, 4))
* * * * *Case Is = ".txt", ".prn", ".csv"
* * * * * * *Wb.Worksheets(1).UsedRange.Columns.AutoFit
* * *End Select
End Sub

Save your personal.xls.
Close excel and reopen it. *Your personal.xls workbook show open and set up this
application event.

If you're new to macros, you may want to read David McRitchie's intro at:http://www.mvps.org/dmcritchie/excel/getstarted.htm

You can read more about those application events at Chip Pearson's site:http://www.cpearson.com/excel/AppEvent.aspx

On 11/26/2011 20:49, zigzagdna wrote:





Whenever I open an excel workbook, or create a new work book, I want
cretain macros to be automatically applied. For example. I want
following workwook open be exceuted to all abobe work books (existing
and new...)"


Private Sub Workbook_Open()


* * * * *MsgBox "Wecome, welcome..."


End Sub


Is there a way of doing it. I have setup this macro in personal.xlsb
file, but it does not get applied when I create a new workbook or open
an existing workbook. It seems to apply only to personal.xlsb file.


Thanks.


--
Dave Peterson- Hide quoted text -

- Show quoted text -


Dave Peterson:

Thanks so much, this is what I was lloking for. I have a book on Excel
macros, but it does not have anything on application events.

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
Apply footer code to all new workbooks Billy Rogers[_2_] Excel Programming 1 November 14th 07 09:01 PM
Use VBA to Apply various Security Levels in Workbooks Tricia Young Excel Programming 8 October 10th 06 05:19 AM
Apply macro to closed workbooks Belinda Robinson Excel Programming 0 July 31st 03 08:09 PM
Apply macro to closed workbooks Belinda & Jamie Excel Programming 5 July 31st 03 05:31 PM
Macro for Pivot Table - Apply to multiple workbooks Nathan Schlaud Excel Programming 0 July 14th 03 04:14 PM


All times are GMT +1. The time now is 01:29 PM.

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"