?
Solved

Excel object

Posted on 2000-04-18
9
Medium Priority
?
127 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 200 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
Industry Leaders: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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