Results 1 to 4 of 4

Thread: Saving Excel file after creating it...

  1. #1

    Thread Starter
    Addicted Member darth vador's Avatar
    Join Date
    Jul 2005
    Posts
    148

    Saving Excel file after creating it...

    I've created an excel file. It works fine. Opens up fine.

    Now I want to save this file.

    Here's my current code.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim excel As New Excel.Application
    3.         excel.Workbooks.Add()
    4.         excel.Range("b1:c1").Select()
    5.         excel.Selection.Font.Bold = True
    6.         excel.Range("b1").Select()
    7.         excel.ActiveCell.Value = "Questions"
    8.         excel.Range("c1").Select()
    9.         excel.ActiveCell.Value = "Answers"
    10.  
    11.         excel.Visible = True

    Now, I want to save the file (either before or after it is displayed to the user)

    I was looking for a excel.saveFile function but can't find it.

    How would I save this?
    something like excel.save(application.startuppath & myvar & ".xls")

    Thanks...

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

    Re: Saving Excel file after creating it...

    Its under the Workbooks collection.
    VB Code:
    1. Dim oWB as excel.workbook
    2.  
    3. '...
    4. '...
    5.  
    6. oWB = excel.Workbooks.Add()
    7. '...
    8. '...
    9. oWB.SaveAs FileName:="C:\Test.xls"
    10. oWB.Saved = True
    11. oWB.Close
    12. '...
    You should always use the workbook set to an object variable when working with workbooks.


    Ps, Gangsta Yoda says: Use the Force Darth. I am your Dad!
    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

    Thread Starter
    Addicted Member darth vador's Avatar
    Join Date
    Jul 2005
    Posts
    148

    Re: Saving Excel file after creating it...

    That was it. Thanks!

    btw, you may know the power of VB.net. But you do NOT know the power of the Dark Side!

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

    Re: Saving Excel file after creating it...

    No, you dont know the power of the Jedi as I had to school you on how to do this.


    I see you changed your avatar. Now we can battle it out via coding.
    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