Runtime Error '91': Objectvariable Or With-blockvariable Not

endor

New Member
Joined
Oct 17, 2006
Messages
2
I get this error message (I hope I have translated it correctly from German to English) when running the following code:
Code:
On Error Resume Next 
oExl.Workbooks.Open filename 
If Err > 0 Then 
    MsgBox "Could not open Excel file.", vbExclamation, "Fileerror" 
    Exit Sub 
End If 
 
On Error Goto 0 
 
With oExl.ActiveWorkbook.Worksheets(1) 
    lastcol = CInt(.Cells.Find(What:="*", After:=.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column) 
    lastrow = CInt(.Cells.Find(What:="*", After:=.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row) 
    col1 = CInt(.Cells.Find(str4, LookIn:=xlValues).Column) 
    row1 = CInt(.Cells.Find(str4, LookIn:=xlValues).Row)

It looks as if the Blockvariable is set. The interesting point is, that the error occurs when getting col1, not lastcol. I do not really see a difference between requesting lastcol and col1. col1 and row1 have been used and initialized previously. When debugging I also notice that the lastcol variable already has the correct value.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Stormseed

Banned
Joined
Sep 18, 2006
Messages
3,274
Re: Runtime Error '91': Objectvariable Or With-blockvariable

I get this error message (I hope I have translated it correctly from German to English) when running the following code:
Code:
On Error Resume Next 
oExl.Workbooks.Open filename 
If Err > 0 Then 
    MsgBox "Could not open Excel file.", vbExclamation, "Fileerror" 
    Exit Sub 
End If 
 
On Error Goto 0 
 
With oExl.ActiveWorkbook.Worksheets(1) 
    lastcol = CInt(.Cells.Find(What:="*", After:=.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column) 
    lastrow = CInt(.Cells.Find(What:="*", After:=.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row) 
    col1 = CInt(.Cells.Find(str4, LookIn:=xlValues).Column) 
    row1 = CInt(.Cells.Find(str4, LookIn:=xlValues).Row)

It looks as if the Blockvariable is set. The interesting point is, that the error occurs when getting col1, not lastcol. I do not really see a difference between requesting lastcol and col1. col1 and row1 have been used and initialized previously. When debugging I also notice that the lastcol variable already has the correct value.

Hey mate....

Check this out ::

http://www.officekb.com/Uwe/Forum.aspx/excel-prog/34431/Runtime-error-91
 

Forum statistics

Threads
1,136,431
Messages
5,675,806
Members
419,586
Latest member
RoteichA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top