Solved

Excel OLE Problem

Posted on 1999-01-11
6
235 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
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now