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
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