VBA update filename and path upon saving

2019-08-26 22:25发布

问题:

I've tried using the following codes below, but none will give me an active field that will update upon saving. I want the file path and name. Maybe you can help. Thanks.

ActiveDocument.Name - gives the name of the document, without path information.

回答1:

As @braX says

Use FullName to get the file name and path. Note FullName will only contain the file path AFTER you have saved the document once!

' Saved
ActiveDocument.FullName ' -> C:\Documents\Doc1.docx

' Unsaved
ActiveDocument.FullName ' -> Document2

use Name to get the file name only

ActiveDocument.Name ' -> Doc1.docx