ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How mk code applicable to any active workbook? (https://www.excelbanter.com/excel-programming/294130-how-mk-code-applicable-any-active-workbook.html)

Chet Shannon

How mk code applicable to any active workbook?
 
I created a macro that will create footers for the active
wkbk, but does anyone know how to get a given macro to
run on any workbook that is open and not just the active
workbook? In other words I want this macro to be
executed on any workbooks that happen to be active at the
time. (Rather than be executable soley on one specific
macro.)

Thanks,
Chet




Bob Phillips[_6_]

How mk code applicable to any active workbook?
 
Hi Chet,

I think you are referring to application events. You can set it up so that
all workbooks print a value. To do this you need application events, and put
this is a separate workbook, such as Personal.xls, and then any workbook
will adopt these properties. No need to code each workbook with it.

This is what you need to do.

Firstly, all of this code goes in the the designated workbook.

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

Option Explicit

Public WithEvents App As Application

Private Sub App_WorkbookBeforePrint(ByVal Wb As Workbook, Cancel As Boolean)
With Wb.ActiveSheet
.PageSetup.LeftFooter = "some text"
End With
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)

"Chet Shannon" wrote in message
...
I created a macro that will create footers for the active
wkbk, but does anyone know how to get a given macro to
run on any workbook that is open and not just the active
workbook? In other words I want this macro to be
executed on any workbooks that happen to be active at the
time. (Rather than be executable soley on one specific
macro.)

Thanks,
Chet






Chet Shannon

How mk code applicable to any active workbook?
 
Thanks Bob... ! I will give it a try...
Chet
-----Original Message-----
Hi Chet,

I think you are referring to application events. You

can set it up so that
all workbooks print a value. To do this you need

application events, and put
this is a separate workbook, such as Personal.xls, and

then any workbook
will adopt these properties. No need to code each

workbook with it.

This is what you need to do.

Firstly, all of this code goes in the the designated

workbook.

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

this code

Option Explicit

Public WithEvents App As Application

Private Sub App_WorkbookBeforePrint(ByVal Wb As

Workbook, Cancel As Boolean)
With Wb.ActiveSheet
.PageSetup.LeftFooter = "some text"
End With
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)

"Chet Shannon"

wrote in message
...
I created a macro that will create footers for the

active
wkbk, but does anyone know how to get a given macro to
run on any workbook that is open and not just the

active
workbook? In other words I want this macro to be
executed on any workbooks that happen to be active at

the
time. (Rather than be executable soley on one specific
macro.)

Thanks,
Chet





.



All times are GMT +1. The time now is 04:02 AM.

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