Word VBA: Getting the Path to an Active Document

I’ve described a PowerPoint VBA macro to get the path to an active presentation.
Today, I’ll show you a similar macro on Microsoft Word.

Macro Example

The following Word VBA macro shows a message box with the path to an active document. (The path does not include the file name.)

Sub GetActiveDocumentPath()

  MsgBox ActiveDocument.Path

End Sub

Description

ActiveDocument property

  ActiveDocument...

The Application.ActiveDocument property returns an active Document object.

obj-Word-Application-ActiveDocument

The ActiveDocument property is a member of the Word.Global class, so we can omit the Application property.

obj-Word-ActiveDocument

Document.Path property

  ActiveDocument.Path

The Document.Path property (ActiveDocument.Path) returns a path to the document.

obj-Word-Document-Path

MsgBox function

The code: ActiveDocument.Path is set to the parameter of a MsgBox function.

Sub GetActiveDocumentPath()

  MsgBox ActiveDocument.Path

End Sub

So, a message box shows the path to an active document.

Properties

http://www.relief.jp/itnote/archives/003496.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007