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
Printable View
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
Depends. Are you going to want to automate them or just open them?
open them but can also work/modify contents with the opened fileQuote:
Originally Posted by RobDog888
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