Opening a word document using Excel VB
Opening a word document using Excel VB
(OP)
Anyone know if this is possible? I want to be able to open a word proforma document by clicking a button in an excel spreadsheet, but after reading the "help" files, I'm a little confused as to whether it is possible to do. Any help would be appriciated!
Cheers
James
Cheers
James





RE: Opening a word document using Excel VB
There are several ways to do this.
One method is to select a cell, right click and
select HYPERLINK. Browse to your word document and click OK. Works like any other hyperlink. Word will open the document.
You can also add an Autoshape to your spreadsheet and assign a hyperlink via the right click as well.
RE: Opening a word document using Excel VB
RE: Opening a word document using Excel VB
Sub OpenWord()
fNameAndPath = "C:\***PATH***\file.doc"
Set wordApp = CreateObject("Word.Application")
wordApp.Documents.Open (fNameAndPath)
wordApp.Visible = True
End Sub
Opening other files is a little more difficult.
RE: Opening a word document using Excel VB
CODE
OpenDocument = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocumentWithPath, vbNormalFocus)
End Function
CODE
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
Steam Engine enthusiasts: www.essexsteam.co.uk
RE: Opening a word document using Excel VB
I have no idea how I did it, it was back in early 1999. I remember using the VB Help and ObjectBrowser a lot, though. (Particularly their sample code.)
RE: Opening a word document using Excel VB
I had a few problems with getting it to launch a new document from the template rather than just opening the template and, in this case, the template must be located in the same directory as the spreadsheet. However here is what I ended up with:
Private mobjWordApp As Word.Application, wbXL As excel.Workbook
Private Sub CommandButton1_Click()
Dim templName As String
Dim tPath As String
tPath = ThisWorkbook.Path
templName = "filename.dot"
Set mobjWordApp = New Word.Application
With mobjWordApp
.Visible = True
.WindowState = wdWindowStateMaximize
.Documents.Add Template:=(tPath & Application.PathSeparator _
& templName), NewTemplate:=False, DocumentType:=0
End With
End Sub
Hope this is not too late to be of some use,
G