creator
creator

Reputation: 21

Getting wrong path name in VBScript

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

Upvotes: 1

Views: 628

Answers (1)

Cheran Shunmugavel
Cheran Shunmugavel

Reputation: 8459

You can just use the FullName property.

fullpath = Me.Application.ActiveDocument.FullName

Upvotes: 1

Related Questions