Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell to Word, Open a Doc and run a Macro

Access Howto:

Shell to Word, Open a Doc and run a Macro

by  DougP  Posted    (Edited  )
This is a sample of a command button put on a Access form.
It launches Microsoft Word (any Version) then Opens a document and also can run a Macro. The macro is a Word macro you create in word just like any other macro. For Example the macro could Print the Mail Merged document and then Quit Word bringing you back to Access.

---------------------------------------------------
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
' Button launches Word and opens a specified document
' And runs an optional macro. the macro could print out the word doc and quit

Dim retval As Variant
Dim DocName, MacroName As String
' Drive and Full path to name and location of Word document
DocName = "F:\Somefolder\MyDoc.doc"

'Optional Macro Name. Note Word Macro name cannot have any spaces in it.
'MacroName = "/M" & "MacroName"

'Note full path to Word including Drive and folder
retval = Shell("c:\Microsoft Office97\Office\WinWord.exe" & " " & DocName & MacroName, vbNormalFocus)

Exit_Command19_Click:
Exit Sub

Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click

End Sub
--------------------------------------------------
Here is an FAQ on Creating a WORD Doc to mail merge with Access database query.
FAQ181-271
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top