Solved

Excel object

Posted on 2000-04-18
9
125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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