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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,665
Messages
6,120,804
Members
448,990
Latest member
rohitsomani

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