LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Catching NewSheet-Event in another WorkBook

05.10.2004 12:35, Bob Phillips schrieb:

Hi Bob,

Use application events.

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

'========================================
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 App_WorkbookNewSheet(ByVal Wb As Workbook, ByVal Sh As Object)
Set gwbsNewSheet = sh
End Sub



Thanks for your reply, points me into the right direction
your sample code works. Also I found out, that i can do it all inside the
ThisWorkBook-Module like this (not using event-Classes)

Option Explicit

Dim WithEvents gThisApp As Application
Dim gwkbNew As Workbook
Dim gwksNew As Worksheet

Private Sub Workbook_Open()
Dim wks As Worksheet
Set gThisApp = Application
gThisApp.Workbooks.Open "C:\DATA\x.xls"
gwkbNew.Worksheets.Add
Set wks = gwksNew
wks.Name = "newnewnew"
End Sub

Private Sub gThisApp_WorkbookOpen(ByVal Wb As Workbook)
Set gwkbNew = Wb
End Sub

Private Sub gThisApp_WorkbookNewSheet(ByVal Wb As Workbook, ByVal Sh As Object)
If TypeOf Sh Is Worksheet And Wb Is gwkbNew Then
Set gwksNew = Sh
End If
End Sub


btw is there also an event if you create a new sheet with
someWorkSheet.Copy
NewSheet seems to fire after 'worksheets.Add' (but not .Copy)?


--
Gruesse, Christoph

Rio Riay Riayo - Gordon Sumner, 1979
 
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: Catching only filled cell data sumit Excel Discussion (Misc queries) 1 November 24th 06 12:28 PM
Catching an Open Excel File with VBScript onedaywhen Excel Programming 2 April 6th 04 09:54 AM
Catching an error Shannon Excel Programming 1 December 8th 03 08:22 PM
Pivot Table NewSheet Event Hide Columns Tysone Excel Programming 2 October 15th 03 01:51 AM
[how to] VBA catching close/print in printpreview Héctor Miguel Excel Programming 0 August 16th 03 02:28 AM


All times are GMT +1. The time now is 08:55 AM.

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

About Us

"It's about Microsoft Excel"