我正试图在系统的屏幕上用Lotus脚本打开Microsoft word 2013。它适用于较低版本(2010年及以下),但仅为Microsoft 2013抛出错误... Findwindow(“OppusApp”,Title1)值为0因此抛出处理错误,它必须为1 ..(Title1是标识符引用到Microsoft Word和OppusApp是窗口类名称)。请建议一个解决方法?
代码:
Function WaitForWordtoFinish(PathName As String,DocName As String, ReadOnlyFlag As Integer) As Integer
Dim hwnd As Long
Dim hwnd1 As Long
Dim hwndstate As Long
Dim hwndact As Long
Dim wordobj As Variant
Dim AppTitle As String
Dim AppTitle1 As String
Dim hwndactivate As Long
Dim hwnWord As Long
Dim cnt As Long
Dim ReadTitle As String * 256
If ReadOnlyFlag = 1 Then
AppTitle = "Microsoft Word - " & DocName & " (Read-Only)"
Else
AppTitle = "Microsoft Word - " & DocName
End If
AppTitle1 = "Microsoft Word"
hwndact = GetActiveWindow()
Set wordobj = CreateObject("Word.Basic")
''=====wordobj.AddAddIn templatedir & "acts.dot",1
**hwnWord = FindWindow("OpusApp", AppTitle1)
If hwnWord = 0 Then**
WaitForWordtoFinish = False
Messagebox "Please close all Word Documents prior to opening a Word Document through ACTS.", 0+16 , "Warning - Opened Word Document(s)"
Exit Function
End If
wordobj.Appmaximize "Microsoft Word",1
hwndstate = ShowWindow(hwndact,0)
If ReadOnlyFlag = 1 Then
wordobj.FileOpen PathName & DocName, 0, 1
Else
wordobj.FileOpen PathName & DocName
End If
'=====wordobj.ToolsRevisions 1, 1, 1
wordobj.AddAddIn templatedir & "acts.dot",1
wordobj.ToolsMacro "InterfaceMacro", True
答案 0 :(得分:0)
我只是总结评论中的所有信息并从中得到答案:
在您的代码中,您使用Windows功能" FindWindow"识别您的MS Word窗口。
您的代码的相关行是:
AppTitle1 = "Microsoft Word"
...
hwnWord = FindWindow("OpusApp", AppTitle1)
在较旧的Office版本中,窗口标题的组成如下:
Microsoft word - FileName.doc
在Office 2013中,窗口标题为
FileName.doc - Word
为了使您的示例能够同时使用这两个版本,您需要同时检查两者:
AppTitle = "Microsoft Word - " & DocName
hwnWord = FindWindow("OpusApp", AppTitle)
If hwnWord = 0 Then '- not found, try the other one
AppTitle = DocName & " - Word"
hwnWord = FindWindow("OpusApp", AppTitle)
If hwnWord > 0 then '- Found window...
'- do whatever needed
End If
End If