rsmith1302
New member
- Joined
- Jul 25, 2023
- Messages
- 4
- Programming Experience
- 10+
I’m using VB.Net in Visual Studio 2022. In the following code, writing to the cell works. You can see the new value if you put a watch on it.
Dim ExcelApp As New Excel.Application
Dim ExcelWBs As Excel.Workbooks
Dim ExcelWB As Excel.Workbook
Dim ExcelWS As Excel.Worksheet
ExcelWBs = ExcelApp.Workbooks
ExcelWB = ExcelWBs.Add
ExcelWS = ExcelWB.Sheets.Add
ExcelWS.Cells(1, 1) = "qwerty"
However, trying to read the cell throws an exception. "ExcelWS.Cells(1, 1).Value2" gives the message "Public member 'Value2' on type 'Range' not found." I get the same exception if I try “? ExcelWS.Cells(1, 1).Value2” in immediate mode. Furthermore, autocomplete doesn’t show a Value2 member (but the watch does). And "debug.print(ExcelWS.Cells(1, 1)" gives "Conversion from type 'Range' to type 'String' is not valid."
Why don't the indices turn the Range object into a scalar on a read, while they work on a write (or in a watch)?
Dim ExcelApp As New Excel.Application
Dim ExcelWBs As Excel.Workbooks
Dim ExcelWB As Excel.Workbook
Dim ExcelWS As Excel.Worksheet
ExcelWBs = ExcelApp.Workbooks
ExcelWB = ExcelWBs.Add
ExcelWS = ExcelWB.Sheets.Add
ExcelWS.Cells(1, 1) = "qwerty"
However, trying to read the cell throws an exception. "ExcelWS.Cells(1, 1).Value2" gives the message "Public member 'Value2' on type 'Range' not found." I get the same exception if I try “? ExcelWS.Cells(1, 1).Value2” in immediate mode. Furthermore, autocomplete doesn’t show a Value2 member (but the watch does). And "debug.print(ExcelWS.Cells(1, 1)" gives "Conversion from type 'Range' to type 'String' is not valid."
Why don't the indices turn the Range object into a scalar on a read, while they work on a write (or in a watch)?