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: 51
Default Object variable or With block variable error

I'm not sure if this will solve your problem, but I would not use the
New keyword in the variable declaration. Better do a Set AppClass = New
EventClass. Also, the rng.Select in the Event Module seems to be
redundant, because you work on the range, not on the selection.

Regards,
Steve
www.stkomp.com

Tony Logan wrote:
I'm getting an error I can't explain.

The code I have is supposed to run whenever a workbook is opened. The active
sheet is searched for a particular font. If the font is found, the user gets
a message box.

This works fine as long as I already have Excel running.

However, if Excel is not running and I try opening an Excel file from
Windows Explorer, for instance, I get a run-time error "Object variable or
With block variable not set" at the first line of code.

One other bit of info that may or may not be useful: after this error
occurs, the code no longer works, no matter how many additional files I open.
I have to close out of Excel and then restart it to get the code working
again.

I'm running Excel 2003 on Windows XP with SP2. The code is stored in an
add-in (.xla file) I keep in the XLSTART folder.

Here's the code in the EventClass Class Module:

Option Explicit

Public WithEvents App As Application

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

Dim c As Variant
Dim rng As Range

Set rng = Excel.ActiveSheet.UsedRange
rng.Select
For Each c In rng
If c.Font.Name Like "Arial" Then
MsgBox "found one"
Range("A1").Select
Exit Sub 'if we find just one occurrence, we're done
End If
Next

End Sub


And here's the code in the This Workbook module:

Option Explicit

Dim AppClass As New EventClass

Private Sub Workbook_Open()
Set AppClass.App = Application
End Sub


 
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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Getting inconsistent Error 91-Object variable or With block variable not set mfq Excel Programming 0 December 14th 05 06:08 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


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