Solved

Excel object

Posted on 2000-04-18
9
124 Views
Last Modified: 2010-05-02
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"
0
Comment
Question by:damienm
  • 5
  • 3
9 Comments
 
LVL 22

Accepted Solution

by:
ture earned 50 total points
ID: 2726125
damienm,

The error is because this line...
  Set ExcelSheet = CreateObject("Excel.Sheet")
....creates a WORKBOOK and not a SHEET.

A Workbook does not have a Cells property. Therefore, this line generates an error:
  ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"

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

Ture Magnusson
Karlstad, Sweden
0
 

Expert Comment

by:skyblue011400
ID: 2726130
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).
0
 

Expert Comment

by:skyblue011400
ID: 2726133
skyblue changed the proposed answer to a comment
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:ture
ID: 2726152
Thanks, skyblue!
0
 

Expert Comment

by:skyblue011400
ID: 2726159
it's the first time i have ever posted anything.  i was surprised to see your answer popup a minute before mine!
0
 

Expert Comment

by:skyblue011400
ID: 2726167
it's the first time i have ever posted anything.  i was surprised to see your answer popup a minute before mine!
0
 
LVL 22

Expert Comment

by:ture
ID: 2726170
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
0
 

Expert Comment

by:skyblue011400
ID: 2726186
.. and maybe i'll know not to press refresh next time!
0
 
LVL 2

Author Comment

by:damienm
ID: 2726255
Hardluck Skyblue a few seconds earlier and you would have 50 points,

Thanks Ture, Skyblue
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question