1

I want to get the exact path of the active word document. I have written the below code. The code works fine if one word document is open, but when I open a second document and run it the path shows as "My Documents". Even in the first document, if I run now it shows "My Documents". The code is:

Sub NewMenuMacro()
   Dim myMenuItem As Object

    Dim objIE As Object
    Dim folderName
    folderName = "..\.."
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
      Dim fullpath
     fullpath = fso.GetAbsolutePathName(Me.Application.ActiveDocument)

  If fso.FileExists(fullpath) Then
  Dim objFile
        ' fullpath = fso.GetAbsolutePathName(Me.Application.ActiveDocument)
     Set objFile = fso.GetFile(fullpath)
    ActiveDocument.SaveAs (objFile.path)
    fullpath = fso.GetAbsolutePathName(objFile)

   Else
    ActiveDocument.Save
    fullpath = fso.GetAbsolutePathName(Me.Application.ActiveDocument)
   End If
0

1 Answer 1

1

You can just use the FullName property.

fullpath = Me.Application.ActiveDocument.FullName
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.