Here is my scenario: User merges a Word document, I have a button on the Quick Access toolbar which execute a macro which uses a Shell Execute to spawn an application passing it a parameter.
This works, however the parameter I need is the name of the Word document. When I query the active document it is called, "Form Letters."
Is there a way to get the Word document (template) name in VBA code after the document has merged? I know Word changes the name after it merges, I need the Word document name that contains the merge fields.
Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub RunYourProgram()
l = Len(ActiveDocument)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The line below retrieves name, "FORM LETTER"(strips off .doc)
' rather than name of Word document template
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Doc_Name = Mid(ActiveDocument, 1, l - 4)
Dim RetVal As Long
On Error Resume Next
RetVal = ShellExecute(0, "open", "M:\gendoc\FG_To_ECF.exe", _
Doc_Name, "c:\Certificates", SW_SHOWNORMAL)
End Sub