在VBScript中获取错误的路径名称

时间:2011-05-05 05:10:53

标签: vbscript

我想获得活动word文档的确切路径。我写了下面的代码。如果一个word文档打开,代码工作正常,但当我打开第二个文档并运行它时,路径显示为“我的文档”。即使在第一个文档中,如果我现在运行它会显示“我的文档”。代码是:

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

1 个答案:

答案 0 :(得分:1)

您可以使用FullName属性。

fullpath = Me.Application.ActiveDocument.FullName