Open a Word Document from Excel
This Microsoft Excel macro will open a Microsoft Word document from excel. With this macro, you can open any word document on your computer. This is a small but cool macro; you can attach it to a button or checkbox and then, whenever a user clicks the button or checkbox, have a specified Microsoft word document open.
You can change the word document that will open by changing this line of code
objWord.Documents.Open "C:\test.doc" so that the directory and file name, including extension, point to the desired file on your computer.
Where to install the macro: Module
Open a Word Document from Excel
Sub Open_Word_Document()
'Opens a Word Document from Excel
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
'Change the directory path and file name to the location
'of your document
objWord.Documents.Open "C:\test.doc"
End Sub
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007
Go to Tools > Macros > Visual Basic Editor
For Excel 2007
Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
Hi is it possible to open a word document in excel and if so how..Thanks
Is it possible to open a word document in Excel and hopefully have the columns align?
I am really really hoping so. I scanned some data and now need to review it in Excel.
Help please... anyone... appreciate it.
S.
Hi all I'm trying to open a word document from excel using VBA. Here is my code.
Code:
Sub Help_Click()
Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\Help.doc")
wdApp.Visible = True
wdDoc.Activate
End Sub
When I run the code I get the following error "User-defined type not defined". The line of code is highlighted in yellow. Any help will be greatly apprecaited.
I use excel to launch other applications like PowerPoint and Word. I can specifically go to a PowerPoint Page when I open it from Excel. How do I go to a specific page of a word document that I have just opened from Excel?
Here is some code that I currently use (That works great).
setup: Shx is a sheet or slide number, Tx is used as an idicator of file type.
This opens a PowerPoint file and goes to a specific slide.
If Tx = "File.ppt" Then
If IsNumeric(Shx.Value) Then
Set PPT = GetObject(Px & Fx)
PPT.Application.Visible = True
PPT.Application.Activate
If Shx > 0 Then Set Slide = PPT.Slides(Shx.Value)
Slide.Select
Exit Sub
End If
End If
Here is what I have for the Word document. This one will not goto a specific page like the one above. (This does not work).
If Tx = "File.doc" Then
Tx.Select
Set Word = GetObject(Px & Fx)
Word.Application.Visible = True
Word.Application.Activate
If Shx > 0 Then Word.Goto Shx.Value
Exit Sub
End if
I can't seem to figure this one out.
I have a Toolbar button with a hyperlink to a MS WORD document, I would like to make it a Macro.
Hi All
Wonder if you can help. I know how to open a word document in through Excel VBA. Could you advise on the could that would allow me to select the fine I want to open from a specific directory?
Regards,
Hi i need to open a word document from an excel spreadsheet.
Please help
Hi,
I'm trying to select an already open word document from an excel macro. If the document isn't open, I can do this:
Code:
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(fileName:="C:\Filename.doc")
But, if it's already open, I can't seem to grab it. This doesn't work:
Code:
Set objDoc = Documents("Filename.doc")
Can someone point me in the right direction?
Thanks in advance!
I would like to know by vba if a Word document is open
the same way we do to check if a excel file is open, eg:
'Returns True is the Workbook Exists
'This Function works for Excel and Word Files.
Code:
Function Fx_FileExists(FName As String) As Boolean
Fx_FileExists = (Dir(FName) "")
End Function
'Returns True is the Workbook is open
'This Function works for Excel but it does not work for Word Files.
Code:
Function Fx_FileIsOpen(WkbName As String) As Boolean
Dim X As Workbook
On Error Resume Next
Set X = Workbooks(WkbName)
If Err = 0 Then Fx_FileIsOpen = True
End Function
Any Idea to get a Function that returns if a Word File is OPEN??
Hi Excel Experts,
Is there a macro that can open a Microsoft Word document? I've had a look through the forum, but cannot see what I am after.
Any help is appreciated.
Cheers