Link to home
Start Free TrialLog in
Avatar of damienm
damienmFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel object

I have this code which I copyed straight from the help files

Private Sub Command1_Click()
' Declare an object variable to hold the object
' reference. Dim as Object causes late binding.
Dim ExcelSheet As Object

Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Visible = True
' Place some text in the first cell of the sheet.
ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"
' Save the sheet to C:\test.doc directory.
ExcelSheet.SaveAs "C:\temp\TEST1.xls"
' Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit
' Release the object variable.
Set ExcelSheet = Nothing

End Sub

but when it gets to the line

ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"

I get the error message "Object doesn't support this message or property"
ASKER CERTIFIED SOLUTION
Avatar of ture
ture

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skyblue011400
skyblue011400

Try changing the problem line to:

ExcelSheet.Sheets(1).Cells(1, 1).Value = "This is column A, row 1"

You can get help on the Excel Application object properties and methods by adding a reference to the Microsoft Excel Object Library in your project and using the object browser (press F2).
skyblue changed the proposed answer to a comment
Thanks, skyblue!
it's the first time i have ever posted anything.  i was surprised to see your answer popup a minute before mine!
it's the first time i have ever posted anything.  i was surprised to see your answer popup a minute before mine!
Welcome to EE, skyblue! It's good to see that you are beginning to post solutions. Keep at it! You'll beat me next time...

It was nice of you to withdraw your answer when you noticed my post with the same solution.

/Ture
.. and maybe i'll know not to press refresh next time!
Avatar of damienm

ASKER

Hardluck Skyblue a few seconds earlier and you would have 50 points,

Thanks Ture, Skyblue