TomBarsh
Structural
- Jun 20, 2002
- 1,003
Using VBA (and Excel 2007), I have a problem with a line where I want to change the cell referenced by a name.
All I am trying to do is assign an existing name to a new cell. In simplest form:
Sub Red()
Dim WB As Workbook
Dim WS As Worksheet
Set WB = ActiveWorkbook
Set WS = Worksheets("Sheet1")
WS.Range("myCell").Offset(4, 0).Name = "myCell"
End Sub
This version works just fine. I can run it all day long.
The problem is if I change the line
WS.Range("myCell").Offset(4, 0).Name = "myCell"
To
WB.WS.Range("myCell").Offset(4, 0).Name = "myCell"
In the latter case I get the error "Object doesn't support this property or method"
In the original case, it is implicit that the range where the name is to be changed is in the active workbook. But I want the operation to act on another (open) workbook, one that is not active. Thus my use of setting variable WB to "some" workbook. For this sample I even set WB to the active workbook...and I still get the error!
Can someone explain this please? Thank you.
All I am trying to do is assign an existing name to a new cell. In simplest form:
Sub Red()
Dim WB As Workbook
Dim WS As Worksheet
Set WB = ActiveWorkbook
Set WS = Worksheets("Sheet1")
WS.Range("myCell").Offset(4, 0).Name = "myCell"
End Sub
This version works just fine. I can run it all day long.
The problem is if I change the line
WS.Range("myCell").Offset(4, 0).Name = "myCell"
To
WB.WS.Range("myCell").Offset(4, 0).Name = "myCell"
In the latter case I get the error "Object doesn't support this property or method"
In the original case, it is implicit that the range where the name is to be changed is in the active workbook. But I want the operation to act on another (open) workbook, one that is not active. Thus my use of setting variable WB to "some" workbook. For this sample I even set WB to the active workbook...and I still get the error!
Can someone explain this please? Thank you.