ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "Run-time error 91: Object variable or With block not set" (https://www.excelbanter.com/excel-programming/287453-run-time-error-91-object-variable-block-not-set.html)

Snedker

"Run-time error 91: Object variable or With block not set"
 
This code is run from a VB6-application. Could someone tell my why the
line I've pointed out works first time the code is run, but fails the
second time (with error given in subj.)

Before opening kontrolkort.xls it is not opened by any other
application.

It seems xloW is Nothing, but why...I set it at the beginning?

'---code begin

Dim xlo As excel.Application
Dim xloW As excel.Workbook

Dim myCount As Integer, x As Integer, NewMeasure As Integer
Dim isEven As Boolean

Set xlo = New excel.Application
Set xloW = xlo.Workbooks.Open("u:\excel\kontrolkort.xls")

xloW.Application.Visible = True
xloW.Worksheets(1).Range("G42").Value = Me.Antal_n

'--alot of code-cut---

With xloW.Worksheets(1)
If NewMeasure = CInt(Me.Antal_n) Then
If isEven = False Then
ActiveCell.Offset(11 - (CInt(Me.Antal_n) - 1),
0).Activate
NewMeasure = 0
isEven = True
Else
ActiveCell.Offset(-(11 + (CInt(Me.Antal_n) +
1)), 1).Activate
NewMeasure = 0
isEven = False
End If
End If

' ******** Error on next line *********
ActiveCell.Value = CSng(Me.List1.Text) ' <------
ActiveCell.Offset(1, 0).Activate
End With

Set xloW = Nothing
Set xlo = Nothing

'---code end

I'm not closing the excel file since I wish to keep working in it. But
as said: before this code is run the second time, the file will be
closed.

Also, after this code is run my VB-application is blinking on the
taskbar as if it's still pendling something...any ideas?


Regards /Snedker


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com