LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Any way to call a worksheet method that may or may not exist?

I'm adding a whole bunch of little formatting wedges in VBA on individual
sheets as necessary. I want to call then on workbook save. This works:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Sheet3.DoTheKludges
Sheet4.DoTheKludges
Sheet6.DoTheKludges
Sheet9.DoTheKludges
Sheet10.DoTheKludges

End Sub

But it's irredeemably ugly and unmaintainable and doesn't scale well as
sheets get added to or subtracted from this list.

So I was thinking of something along these lines:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Dim objWks As Worksheet

For Each objWks In Me.Worksheets

On Error Resume Next
objWks.DoTheKludges
On Error Goto 0

Next

End Sub

Of course, this doesn't work since, I'm guessing, the objWks.DoTheKludges
method call can't be resolved when the runtime compile occurs and that isn't
trapped by the On Error.

Any thoughts how to get around this?

 
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
Copy Worksheet to a new Workbook creating if it doesn't exist and add more Worksheets if it does exist [email protected] Excel Programming 4 June 18th 06 06:08 PM
Import a CodeModule then call its method in Workbook_Open() [email protected] Excel Programming 7 June 17th 06 09:50 AM
GetObject method not work after Call Shell Method ben Excel Programming 8 February 21st 06 03:45 PM
How do I call a method in VB from Excel with JUST code? Doseeson Excel Programming 2 May 28th 05 12:26 AM
How do I call a method in VB from Excel with JUST code? K Dales[_2_] Excel Programming 0 May 27th 05 09:57 PM


All times are GMT +1. The time now is 10:32 PM.

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"