VBA Documents.Open 姓名 = 总是 "Document1"

VBA Documents.Open Name = always "Document1"

我正在尝试通过带有 Documents.Open 的字符串打开一个 word .docm 文件。它可以工作并打开文件,但在 WordHandle.Documents(x) 内。名称始终为 "Document1"。打开的文档也被命名为 "Document1"

我做错了什么?

Sub FileOpen(ByVal fileName As String)
    If Not gb_WordObjSet Then
           Exit Sub
    End If

    If Not FileExists(fileName) Then
        Exit Sub
    End If

    With gh_WordObject
        .Documents.Open fileName:=fileName, OpenAndRepair:=True

        With .ActiveWindow.View
            .Type = 3
            .ShowAll = True
        End With
    End With
End Sub

fileName 例如= "C:\temp150702161254.docm"

gh_WordObject是这样初始化的

Set gh_WordObject = CreateObject("Application.Word")

这与您使用 "Open and Repair option" 在 Word 中手动打开文档时看到的行为相同。要查看此内容,请在文件打开对话框中转到 select 您的文档,然后单击打开旁边的下拉箭头并选择 "Open and Repair"。这将在原始文档的基础上创建一个新文档。

要正常打开文档,去掉OpenAndRepair参数:

gh_WordObject.Documents.Open FileName:=s_DokFileName 

或将其设置为 False:

gh_WordObject.Documents.Open FileName:=s_DokFileName, OpenAndRepair:=False