Problem trying to use Excel objects in VS 2005 Express - Worksheet

T

Tim

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top