【发布时间】:2015-09-01 17:50:45
【问题描述】:
这是我的场景:用户合并了一个 Word 文档,我在快速访问工具栏上有一个按钮,该按钮执行一个宏,该宏使用 Shell Execute 来生成一个应用程序,向它传递一个参数。
这可行,但是我需要的参数是 Word 文档的名称。当我查询活动文档时,它被称为“套用信函”。
文档合并后,有没有办法在 VBA 代码中获取 Word 文档(模板)名称?我知道 Word 在合并后会更改名称,我需要包含合并字段的 Word 文档名称。
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
【问题讨论】:
-
谢谢。忘记缩进代码了。