ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ActiveCell not recognized (https://www.excelbanter.com/excel-programming/287156-activecell-not-recognized.html)

Snedker

ActiveCell not recognized
 
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


All times are GMT +1. The time now is 04:43 PM.

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