Results 1 to 4 of 4

Thread: [RESOLVED] Writing to Excel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    149

    Resolved [RESOLVED] Writing to Excel

    Hi guys -

    I got the following from vb5 help:

    Dim ExcelSheet As Object

    Set ExcelSheet = CreateObject("Excel.Sheet")
    ExcelSheet.Application.Visible = True
    ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"

    I get an error on the last line: "Object doesn't support this property or method." What's wrong?

    Please help.

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Writing to Excel

    Exactly which version of the Excel control do you have referenced?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Writing to Excel

    Welcome to the Forums.

    What version of Excel are you using? Do you need to support different versions of Excel?

    This will work.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim oApp As Object
    5.     Dim oWB As Object
    6.     Dim oSht As Object
    7.     Set oApp = CreateObject("Excel.Application")
    8.     oApp.Visible = True
    9.     Set oWB = oApp.Workbooks.Add
    10.     Set oSht = oWB.Sheets("Sheet1")
    11.     oSht.Cells(1, 1).Value = "This is column A, row 1"
    12.     oWB.Close SaveChanges:=True, FileName:="C:\Book1.xls"
    13.     Set oSht = Nothing
    14.     Set oWB = Nothing
    15.     oApp.Quit
    16.     Set oApp = Nothing
    17. End Sub
    Moved from Classic VB forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    149

    Re: Writing to Excel

    Thanks! That was quick - and it worked!

    FYI, I am using Access 97 and have the Excel 8.0 Reference installed in vb5 Pro.

    Salud!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width