S
Snedker
I've got a VB6-application with a command button, which holds this
code:
'---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
--- whole lotta code left out ----
ActiveCell.Value = CSng(Me.List1.Text) ' <------
ActiveCell.Offset(1, 0).Activate
End With
NewMeasure = NewMeasure + 1
End If
Next x
Set xloW = Nothing
Set xlo = Nothing
'---code end
The first time I run the code, everything is fine and the ActiveCell
is given a value. But the second time it fails on the line given with
arrow. Why? It fails with:
"Run-time error 91: Object variable or With block not set"
It is the xloW variable that is nothing. Why isn't it set the second
time?
Thanks in advance!
Regards, Snedker
code:
'---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
--- whole lotta code left out ----
ActiveCell.Value = CSng(Me.List1.Text) ' <------
ActiveCell.Offset(1, 0).Activate
End With
NewMeasure = NewMeasure + 1
End If
Next x
Set xloW = Nothing
Set xlo = Nothing
'---code end
The first time I run the code, everything is fine and the ActiveCell
is given a value. But the second time it fails on the line given with
arrow. Why? It fails with:
"Run-time error 91: Object variable or With block not set"
It is the xloW variable that is nothing. Why isn't it set the second
time?
Thanks in advance!
Regards, Snedker