Excel is a handy and powerful spreadsheet. Microsoft Word offers the best document creation tools in a word processor application. Using these 2 applications simultaneously makes a very powerful office suite for management of numerical data and advanced presentation. Microsoft was provided VBA to use functionality of Word from Excel. The instruments to develop and execute VBA are available in both Word as well as Excel.
- Open Microsoft Excel.
- Open macro menu by tabbing "Alt" key and "F8" key on your keyboard.
- Type "Word_Edit" in Macro name box and press "Create".
- Enter following code in "Word_Edit":
' 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 "Adding new text to the document"
' Save the document.
oWord.ActiveDocument.SaveAs Filename:="c:\newdoc.doc"
' Quit Word.
oWord.Quit
' Clear the variable from memory.
Set oWord = Nothing- Click "Tool" tab and click "References" tab. Tick "Microsoft Word 12.0 object library" then press "OK" button.
- Tab "Alt" key and "F8" key. Select macro "Word_Edit" and select "Run" tab. After execution of macro a new Word document on the "C:" hard drive called "newdoc.doc" will be created.



Reply With Quote
Copyright Techfuels
Bookmarks