|
-
Apr 11th, 2005, 11:38 AM
#1
Thread Starter
Junior Member
opening files(word and excel) from vb
hi!
how can i open a file wordfile or excelfile from vb.i have a combo containing file names as a.doc,b.xls,c.doc etc. if i select a.doc from combo then this file should be opened.same is for others
do reply
ashish sharma
-
Apr 11th, 2005, 11:40 AM
#2
Re: opening files(word and excel) from vb
Depends. Are you going to want to automate them or just open them?
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 
-
Apr 11th, 2005, 11:45 AM
#3
Thread Starter
Junior Member
Re: opening files(word and excel) from vb
 Originally Posted by RobDog888
Depends. Are you going to want to automate them or just open them?
open them but can also work/modify contents with the opened file
-
Apr 11th, 2005, 12:21 PM
#4
Re: opening files(word and excel) from vb
Here is something to get you started.
VB Code:
Option Explicit
'Add a reference to MS Excel xx.0 Object Library
'Add a reference to MS Word xx.0 Object Library
Private moAppXL As Excel.Application
Private moAppWD As Word.Application
Private Sub Command1_Click()
Select Case Right(Combo1.Text, InStr(1, Combo1.Text, ".") - 1) 'doc, xls, etc
Case "doc"
Dim oDoc As Word.Document
Set oDoc = moAppWD.Documents.Open(Combo1.Text)
moAppWD.Visible = True
Case "xls"
Dim oWB As Excel.Workbook
Set oWB = moAppXL.Workbooks.Open(Combo1.Text)
moAppXL.Visible = True
Case Else
MsgBox "File not found or extension not listed!", vbOKOnly + vbExclamation
End Select
End Sub
Private Sub Form_Load()
Set moAppXL = New Excel.Application
Set moAppWD = New Word.Application
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If TypeName(moAppXL) <> "Nothing" Then
moAppXL.Quit
End If
If TypeName(moAppWD) <> "Nothing" Then
moAppWD.Quit
End If
Set moAppXL = Nothing
Set moAppWD = 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 
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
|