|
-
Nov 9th, 2005, 11:38 AM
#1
Thread Starter
Addicted Member
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim excel As New Excel.Application
excel.Workbooks.Add()
excel.Range("b1:c1").Select()
excel.Selection.Font.Bold = True
excel.Range("b1").Select()
excel.ActiveCell.Value = "Questions"
excel.Range("c1").Select()
excel.ActiveCell.Value = "Answers"
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...
-
Nov 9th, 2005, 11:51 AM
#2
Re: Saving Excel file after creating it...
Its under the Workbooks collection.
VB Code:
Dim oWB as excel.workbook
'...
'...
oWB = excel.Workbooks.Add()
'...
'...
oWB.SaveAs FileName:="C:\Test.xls"
oWB.Saved = True
oWB.Close
'...
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 9th, 2005, 12:49 PM
#3
Thread Starter
Addicted Member
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!
-
Nov 9th, 2005, 12:52 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|