How to Open a Word Document From Excel VBA




(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)





How to Open a Word Document From Excel VBA
Log in to answer.
Copyright © dBuggr LLC - All Rights Reserved.
nishantbaxi 12:42 am on March 3, 2010
Step 1Open the Microsoft Excel application from the program menu.
Step 2Open the macro menu using the “Alt” and “F8″ keys.
Step 3Enter “Test Macro” into the Macro name box and click on the “Create” button.
Step 4Paste the following code directly below the text “Sub Test”:
‘ Declare the variable.
Dim oWord As Word.Application
‘ Set the variable (runs new instance of Word).
Set oWord = CreateObject(”Word.Application”)
‘ Add a new document.
oWord.Documents.Add
‘ Add some text.
oWord.Selection.TypeText “This is some text.”
‘ Save the document.
oWord.ActiveDocument.SaveAs Filename:=”c:\mydoc.doc”
‘ Quit Word.
oWord.Quit
‘ Clear the variable from memory.
Set oWord = Nothing
Step 5Select “Tool” from the menu bar then select the “References” option. Check the item “Microsoft Word 12.0 object library” then click the “OK” button to continue.
Step 6Press the “Alt” and the “F8″ key to open the window to view the macros available in this spreadsheet. Highlight the macro “Test Macro” and click the “Run” button. After the execution of the macro a new Word document on the “C:” hard drive named “mydoc.doc” has been created.