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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open word and Run word Macro from Access

Status
Not open for further replies.

oggsta

Technical User
Jun 22, 2002
41
0
0
GB
Hello I am trying to open a word document and then run a macro, code 1 opens a word document and code 2 runs a word macro.

How do I combine the code so it will open word and then run the macr

Any help much appreciated.


CODE 1

Private Sub Command596_Click()

Dim stDocName As String

stDocName = "refresh"
DoCmd.RunMacro stDocName

On Error GoTo Err_Command596_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 = "\\Cpsglobal01\company\PLANNING\Informationplanning\Templates\Vodafone\Database\PRE-AP-Parish1.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:\Program Files\Microsoft Office\Office\winword.exe" & " " & DocName & MacroName, vbNormalFocus)

Exit_Command596_Click:
Exit Sub

Err_Command596_Click:
MsgBox Err.Description
Resume Exit_Command596_Click

End Sub

CODE 2
Code to run a Word macro from Access:

Sub RunWordMacro()
Dim WordObj As Word.Application
Set WordObj = CreateObject("Word.Application")
With WordObj
.Run "WordMacroName"
.Quit
End With
End Sub


 
let me see here...

I run an excel macro in my code, so let's see if that code will help you:)

I use this module to open the file, run a macro that's in side of it, and then close the file...
You can get rid of the xlObject.Application.Quit to not have it close the file...

--James



Sub PrintExcelData(varPath As String)
'varPath is a string variable sent from when it's called.
'It contains the path to where my excel file is kept.


Dim xlObject As Object

Set xlObject = CreateObject("Excel.application")
xlObject.Workbooks.Open varPath

xlObject.Application.WindowState = xlMinimized
xlObject.Application.DisplayAlerts = False

'prints the excel file using it's internal print macro.
xlObject.Run ("Badge_Print")


xlObject.Application.Quit
Set xlObject = Nothing



End Sub
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top