Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Sub works sometimes

I am using Excel 2003 Pro on XP Pro.

I have a class module (ICustomSheet) as part of my VBA project (which I
have named BOC) which has the following simple definition;

Option Explicit

Public Sub Initialise() 'UK Spelling
End Sub

The ICustomSheet class instancing property is set to "2 -
PublicNotCreateable" and I am implementing the interface in some
worksheets in my workbook.

The following code works sometimes (especially when I step through in
debug mode) and I am curious why it does not work all of the time.

Dim wbk As Excel.Workbook
Dim sht As Excel.Worksheet
Dim csht As BOC.ICustomSheet

Set wbk = ThisWorkbook

For Each sht In wbk.Worksheets

'find all sheets that implement the custom sheet interface
If TypeOf sht Is BOC.ICustomSheet Then

MsgBox "found"

'cast sheets that implement the interface
Set csht = sht

'and initialise them
csht.Initialise

End If

Next sht

The MsgBox "found" is there for debugging and is most usually not
working. One of my sheets is implementing the interface. Curiously
the code does sometimes work - especially if I am stepping through the
code.

I know I could iterate through the worksheets with an object variable
using late binding but not all sheets will implement my initialise
method and I don't see handling the error as a neat way of doing what I
am trying to do.

Any help would be much appreciated.

Barry-Jon

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
Excel Addin works that works on a template workbook s.jay_k Excel Programming 0 February 15th 06 07:31 PM
it works, it doesn work, its works....and so on. Naz Excel Programming 6 September 30th 05 01:52 PM
How do I convert works file to excel without works software? CatMB Excel Discussion (Misc queries) 1 June 21st 05 04:12 PM
almost works hotherps[_138_] Excel Programming 0 August 28th 04 01:46 PM
One works - One does not? hotherps[_131_] Excel Programming 2 August 27th 04 02:37 PM


All times are GMT +1. The time now is 10:50 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"