Results 1 to 5 of 5

Thread: Interface with Microsoft Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Question Interface with Microsoft Excel

    I have written an application that writes output to a text file. I would prefer to launch Excel and write the output directly to a worksheet where I can have much more flexibility with page formatting for printing.
    How do I write the output (numeric arrays, constants and strings) to the cells of an excel worksheet and launch Excel.
    Alternatively, I could leave the output as a text file if I could get Excel to import it directly into a worksheet template with the required formatting (that is without having to go through the wizard for opening a non-Excel formatted file).
    Any suggestions?

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

    Re: Interface with Microsoft Excel

    Welcome to the Forums.

    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

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

    Re: Interface with Microsoft Excel

    You can get the basics of opening a workbook and writting to it from my code.
    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS Excel xx.0 Object Library
    3. Private moApp As Excel.Application
    4.  
    5. Private Sub Command1_Click()
    6.     Dim oWB As Excel.Workbook
    7.     Dim strName As String
    8.  
    9.     moApp.Visible = True
    10.     Set oWB = moApp.Workbooks.Open("C:\Book1.xls")
    11.     oWB.Sheets(2).Activate
    12.     strName = "RobDog888"
    13.     oWB.Sheets(2).Cells(1, 1).Value = strName 'Write to cell A1
    14.     oWB.Close SaveChanges:=True
    15.     Set oWB = Nothing
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.     Set moApp = New Excel.Application
    20. End Sub
    21.  
    22. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    23.     If TypeName(moApp) <> "Nothing" Then
    24.         moApp.Quit
    25.     End If
    26.     Set moApp = Nothing
    27. End Sub
    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
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Re: Interface with Microsoft Excel

    Thanks robdog.
    I'm running VB3.0 and Excel 97 and it looks like VB3 doesn't support some of your code. Am I'm mising something, is there another way or do I just need to get a more recent release!?

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

    Re: Interface with Microsoft Excel

    Ouch, vb3. Well the Excel 97 stuff should be compatible but what errors are you getting?
    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

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