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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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
Back
Top