在VBScript中获取错误的路径名
我想获得活动word文档的确切路径。我已经写了下面的代码。如果打开一个word文档,代码工作正常,但是当我打开第二个文档并运行它时,路径显示为“我的文档”。即使在第一个文档中,如果我现在运行,它也会显示“我的文档”。代码是:在VBScript中获取错误的路径名,vbscript,Vbscript,我想获得活动word文档的确切路径。我已经写了下面的代码。如果打开一个word文档,代码工作正常,但是当我打开第二个文档并运行它时,路径显示为“我的文档”。即使在第一个文档中,如果我现在运行,它也会显示“我的文档”。代码是: Sub NewMenuMacro() Dim myMenuItem As Object Dim objIE As Object Dim folderName folderName = "..\.." Dim fso Set fso
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
你可以直接使用这个属性
fullpath = Me.Application.ActiveDocument.FullName
你可以直接使用这个属性
fullpath = Me.Application.ActiveDocument.FullName