2
votes

I am trying to open Microsoft word 2013 by lotus script in my screen from the system. It is working fine for lower version ( 2010 and below) but throwing error for just Microsoft 2013... Findwindow("OppusApp", Title1) value is 0 hence throwing the handled error, it must be 1.. ( Title1 is identifier referring to Microsoft Word and OppusApp is window class name). Please suggest a workaround?

Code :

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
1
Please show more code to make others able to reproduce your issue. Like this it is unclear what is happening when. - Tode
I have edited the post, please look into code , The FindWindow function is referring to 0 value, hence throwing popup of Please close all word documents...it should have value 1 - Tinku
What specific version of Microsoft Office 2013 do you have installed? Is it by any chance 64 bit? - Richard Schwartz
And WHERE/HOW is FindWindow, ShowWindow and all the other API- stuff defined? - Tode
@RichardSchwartz It is 32 bit Microsoft word 2013 - Tinku

1 Answers

0
votes

I just sum up all the information in the comments and make an answer from it:

In your code you use the Windows- function "FindWindow" to identify your MS Word Window.

The relevant lines of your code are:

AppTitle1 = "Microsoft Word"
...
hwnWord = FindWindow("OpusApp", AppTitle1)

In older Office versions the window title was composed like this: Microsoft word - FileName.doc

In Office 2013 the window title is FileName.doc - Word

In order for your example to work with both versions you need to check both:

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