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
You can just use the FullName
property.
fullpath = Me.Application.ActiveDocument.FullName
精彩评论