Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Opening a word document using Excel VB

Opening a word document using Excel VB

Opening a word document using Excel VB

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!

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

Thanks WMO! Didn't think of that! I'd still be interested to know if there is a way to open a word document (or any other document for that matter) from a VB Macro.

RE: Opening a word document using Excel VB

FYI I found some code to open word docs from 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

You can readily open any document that is associated with an application by using the FileProtocol handler. I use this function:


Public Function OpenDocument(DocumentWithPath As String) As Long
    OpenDocument = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocumentWithPath, vbNormalFocus)
End Function
From anywhere in your code:


OpenDocument "c:\test\d1.vsd"
On my machine .vsd files are associated with Visio, so running the above code opens the file in a new instance of Visio

Good Luck
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

Not only is it possible to open any Microsoft Office product from a VB Macro, you can also control it too.  My first VB macro opened Access, searched a table for matching records, wrote to the table if there was no duplicate record, then opened Word and performed a mail merge and allowed the user to print and save the mail merge before closing Word again and terminating the macro.

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 did something like this a while back in order to launch a new document from a word template, though it's probably not too elegant to someone who really knows what they are doing.

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,


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close