4

I have a Word document that is already saved and I need to get its existing save directory and/or full file path (i.e. C:\Users\Public\Documents\testDoc.docx).

How can this be acquired from a macro/VBA?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
ikathegreat
  • 2,311
  • 9
  • 49
  • 80
  • `x = documents(1).path & documents(1).name` should get you started (x becomes both the path and the file name.) – tbur Jun 10 '13 at 20:04
  • @tbur, you will need `& "\" &` between `.path` and `.name` properties... – Kazimierz Jawor Jun 10 '13 at 20:13
  • 1
    @KazJaw, Oh, it's so much worse than just the missing backslash. Yes, I missed that (how I'll never know). But **shahkalpesh**'s Answer using `Activedocument.FullName` is superior in every way. – tbur Jun 10 '13 at 20:18
  • FullName is nice, but if the document is on OneDrive, it yields the network name (https://...). But how to get the local filename? – Peter L May 04 '22 at 18:58
  • @PeterL, you can use [this solution](https://stackoverflow.com/a/73577057/12287457) to convert the Url to the local filename. – GWD Oct 23 '22 at 15:42

1 Answers1

18
ActiveDocument.FullName

The above gives the full path to the document, including the file name.

ActiveDocument.Path

The above gives the directory where your document is saved.

ActiveDocument.Name

The above gives the name of the document, without path information.

shahkalpesh
  • 33,172
  • 3
  • 63
  • 88