Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ERROR code 91, when reading excel Sheet

Status
Not open for further replies.

BuskyLusky

Technical User
Mar 13, 2007
5
NO
Hi

I have a problem with this code:
------------------------------------
Dim xlTmp As Excel.Application
Dim xlSht As Excel.Worksheet
------------------------------------
Public Sub Form_Initialize()
Set xlTmp = New Excel.Application
xlTmp.Workbooks.Open "\database.xls"
Set xlSht = xlTmp.Sheets(1)
End Sub
-----------------------------------------
Private Sub CommandButton5_Click()

Label1.Caption = xlSht.Cells.Item(5, 5)

xlTmp.Workbooks.Close
xlTmp.Quit
End Sub
--------------------------------------------
When running this pops up:
Error 91, object variable or With block variable not set.
and this line turns yellow: Label1.Caption = xlSht.Cells.Item(5, 5)

WHY????
 
BuskyLusky,
I thing [tt]Item[/tt] is causing the problem.

If your looking for the data in cell E6 [tt]Label1.Caption = xlSht.Cells(5, 5)[/tt] or [tt]Label1.Caption = xlSht.Range("E6")[/tt]

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top