Solved

Excel OLE Problem

Posted on 1999-01-11
6
240 Views
Last Modified: 2013-12-25
The code shown below, I can't run. Error is "Object dosen't support this property...", line "ExcelSheet.Cells..."
What should I do?

thank you
---------------------------------------------------------
Private Sub Command1_Click()
Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Visible = True
ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"
ExcelSheet.Application.Quit
Set ExcelSheet = Nothing
End Sub
0
Comment
Question by:itacan
[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
6 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 1489554
You can always go to the View|Object browser menu item, select the Excel library, select the sheet object and view what the available properties and methods are.  In this case I looked up Cells and saw that this is a method available to the Application object.  So, maybe you want to be doing CreateObject("Excel.Application")

MD
0
 
LVL 3

Expert Comment

by:cognition
ID: 1489555
I wrote this just for you !
In Project | References set a reference to Microosft Excel Object Library.

    Dim XLApp As New Excel.Application
    Dim XLWS As Worksheet
    Dim XLWB As Workbook
    Dim XLCellRange As Range

    XLApp.Application.Visible = True
    Set XLWB = XLApp.Workbooks.Add()
    Set XLWS = XLWB.Worksheets.Add()
    XLWS.Name = "Worksheet Name"
    XLWS.Columns("A:A").ColumnWidth = 25
    XLWS.Columns("B:B").ColumnWidth = 15
   
    With XLWS.Cells(1, 1)
        .Value = "A cell value"
        .Font.Size = 14
        .Font.Bold = True
    End With


0
 

Author Comment

by:itacan
ID: 1489556
Error : Invalid use of new keyword!!!
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Accepted Solution

by:
cognition earned 100 total points
ID: 1489557
Try the following which uses late binding.

    'Dim XLApp As New Excel.Application
    Dim XLApp As Excel.Application
    Dim XLWS As Worksheet
    Dim XLWB As Workbook
    Dim XLCellRange As Range


    Set XLApp = CreateObject("Excel.Application")

    XLApp.Application.Visible = True
    Set XLWB = XLApp.Workbooks.Add()
    Set XLWS = XLWB.Worksheets.Add()
    XLWS.Name = "Worksheet Name"
    XLWS.Columns("A:A").ColumnWidth = 25
    XLWS.Columns("B:B").ColumnWidth = 15
   
    With XLWS.Cells(1, 1)
        .Value = "PRODUCT SUMMARY SPREADSHEET"
        .Font.Size = 14
        .Font.Bold = True
    End With
0
 
LVL 18

Expert Comment

by:mdougan
ID: 1489558
Hey, everyone is just re-submitting (granted, a more detailed explanation of) my rejected answer!  Here's another thing you could try with your original code that might work.

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

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

MD

0
 
LVL 15

Expert Comment

by:ameba
ID: 1489559
Your line:
   Set ExcelSheet = CreateObject("Excel.Sheet")
will create WorkSheet in Excel 7, but WorkBook in Excel 8.

You can replace your line with this 2 lines:
   Set ExcelBook = CreateObject("Excel.Sheet") ' this will create XLbook
   Set ExcelSheet = ExcelBook.Sheets(1)

Your second line works:
   ExcelSheet.Application.Visible = True
because Workbook also has Application property

but your third line won't work (Workbook doesn't have Cells)


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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

691 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