Solved

Excel object

Posted on 2000-04-18
9
120 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
Comment Utility
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
Comment Utility
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
Comment Utility
skyblue changed the proposed answer to a comment
0
 
LVL 22

Expert Comment

by:ture
Comment Utility
Thanks, skyblue!
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:skyblue011400
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
.. and maybe i'll know not to press refresh next time!
0
 
LVL 2

Author Comment

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

Thanks Ture, Skyblue
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now