ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem trying to use Excel objects in VS 2005 Express - Worksheet (https://www.excelbanter.com/excel-programming/401399-problem-trying-use-excel-objects-vs-2005-express-worksheet.html)

Tim

Problem trying to use Excel objects in VS 2005 Express - Worksheet
 
In the following routine, the ws (Excel.Worksheet object) get set to
a System.__ComObject with 'Children could not be evaluated

What is wrong?

Sub Test()
Dim xlApp As New Excel.Application
xlApp.Visible = True
Dim wb As Excel.Workbook = xlApp.Workbooks.Add
Dim ws As Excel.Worksheet = _
DirectCast(wb.ActiveSheet, Excel.Worksheet)
' ws get set to a System.___ComObject and 'Children could not be evaluated
' Dim ws As Excel.Worksheet = DirectCast(wb.Worksheets(1),
Excel.Worksheet)
' Dim ws As Microsoft.Office.Interop.Excel.Worksheet
For Each ws In wb.Sheets
Debug.Print(ws.Name)
If ws.Name = "Sheet1" Then
ws.Range(ws.Cells(1, 1)).Formula = "XXX"
End If
Next
wb.Close() : xlApp.Quit()
ws = Nothing : wb = Nothing : xlApp = Nothing
End Sub



All times are GMT +1. The time now is 02:33 PM.

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