|
-
Sep 30th, 2005, 10:42 PM
#1
Thread Starter
New Member
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?
-
Sep 30th, 2005, 11:12 PM
#2
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 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 
-
Sep 30th, 2005, 11:16 PM
#3
Re: Interface with Microsoft Excel
You can get the basics of opening a workbook and writting to it from my code.
VB Code:
Option Explicit
'Add a reference to MS Excel xx.0 Object Library
Private moApp As Excel.Application
Private Sub Command1_Click()
Dim oWB As Excel.Workbook
Dim strName As String
moApp.Visible = True
Set oWB = moApp.Workbooks.Open("C:\Book1.xls")
oWB.Sheets(2).Activate
strName = "RobDog888"
oWB.Sheets(2).Cells(1, 1).Value = strName 'Write to cell A1
oWB.Close SaveChanges:=True
Set oWB = Nothing
End Sub
Private Sub Form_Load()
Set moApp = New Excel.Application
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If TypeName(moApp) <> "Nothing" Then
moApp.Quit
End If
Set moApp = Nothing
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 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 
-
Oct 1st, 2005, 06:17 PM
#4
Thread Starter
New Member
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!?
-
Oct 1st, 2005, 06:29 PM
#5
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 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
|