在DocumentBeforeSave中获取保存目的地

时间:2014-12-04 12:27:08

标签: vba word-vba

我有一个模板,我希望在保存发生之前在页脚中显示文档路径。

我已经准备好了DocumentBeforeSave Sub,但是问题是我似乎无法获取文档的目标路径,除非我遗漏了一些东西。

Private WithEvents App As Word.Application

Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    ' UPDATE FOOTER HERE '
End Sub

我首先想到可能参数Doc包含目的地,但我只找到了当前目录。

问题仅在于进行“另存为”时,否则页脚不需要更改。

1 个答案:

答案 0 :(得分:0)

现在你知道你需要保存为' .docm'如果你有VBA代码。并不是说以下内容可以满足您的需求,但它是一个如何查看默认保存路径以及“最新”保存路径的示例。保存此文档的路径。如果有人做了SaveAs,我会将其设置为显示不同的消息(关闭时)。

Option Explicit
Dim strPath     As String

Private Sub Document_Open()
    MsgBox "On Open, default save path is: " & Options.DefaultFilePath(wdDocumentsPath)
    strPath = ActiveDocument.Path
End Sub
Private Sub Document_Close()
    If strPath <> ActiveDocument.Path Then
        MsgBox "Document now in DIFFERENT path." & vbCrLf & _
                "On Close, document was saved at: " & ActiveDocument.Path & vbCrLf & _
                "Originally the document was in path: " & strPath
    Else
        MsgBox "Document still in same path." & vbCrLf & _
                "On Close, document was saved at: " & ActiveDocument.Path & vbCrLf & _
                "Full Path & Name: " & ActiveDocument.FullName
    End If
End Sub