![]() Need some help. I call the Word-object from other application (also App) using VBA-code ( for pushing the data from App to Word-Document). Here is the code (in this code I only want open the word-document from the app): WordApplication=New COMObject('Word.Application'); //App-related code - calling a word-object CurrentDocument=WordApplication.Documents.Open(ThisObject.Path); CurrentDocument.Activate(); WordApplication.Visible=True; WordApplication.Activate(); WordApplication.ActiveDocument.WindowState=1; So, in first line I created the Word-object. In the second line I opened the word-document. Third line - activated the document. Then I made Word-app visible and activated it. Count (and activate) opened Word Documents. Activate Word window from Excel with VBA. Open an Excel document from MS Word Using VBA. ![]() Finally, in last line I want to bring the window of the word-document foreground. By some reason I cannot use native WindowState-constants (such as wdWindowStateMaximize, wdWindowStateMinimize and so on), my app understand only it numeric equivalents. When I debugged my code, I experienced that after line WordApplication.Activate(); the WindowState property becomes '1'. When I assigned 2 or 0 to it, nothing changed, when I assigned '3' to WindowState, I got an error. Problem is that I want to bring my Word-Document to forefront, but this code only activates the word-app in the taskbar (flashing), but not put it to forefront. So I need numeric equivalents for all wdWindowState-constants, or some other way to bring the word-window to forefront. Thanks for your help. Word version - 2003. So, I couldn't resolve this problem via VBScript/Word VBA (via VBScript - possibly 'yes', but this solve is too heavy for this little code). But I found the solution: I used an AutoIt v3 script engine (VBScript-like syntax, many predefined functions for automating Windows GUI and working with windows/processes, etc.). AutoIt provides an extra.dll called AutoItX3 (there are both ways to calling it - via COM and CallDll). So, my code became this view. ObjectAutoIt=New COMObject('AutoItX3.Control'); //calling an AutoIt-object WordApplication=New COMObject('Word.Application'); //App-related code - calling a word-object CurrentDocument=WordApplication.Documents.Open(ThisObject.Path); CurrentDocument.Activate(); WordApplication.Visible=True; WordApplication.Activate(); //Here is - bringing a Word-document window to forefront in one code line ObjectAutoIt.WinSetState(DocumentName,',ObjectAutoIt.SW_MAXIMIZE); I wonder, why setting wdWindowState for ActiveWindow property in Word-VBA code isn't working. This AutoIt code does the same but in other way - and it works fine. So, I couldn't resolve this problem via VBScript/Word VBA (via VBScript - possibly 'yes', but this solve is too heavy for this little code). But I found the solution: I used an AutoIt v3 script engine (VBScript-like syntax, many predefined functions for automating Windows GUI and working with windows/processes, etc.). AutoIt provides an extra.dll called AutoItX3 (there are both ways to calling it - via COM and CallDll). So, my code became this view. ObjectAutoIt=New COMObject('AutoItX3.Control'); //calling an AutoIt-object WordApplication=New COMObject('Word.Application'); //App-related code - calling a word-object CurrentDocument=WordApplication.Documents.Open(ThisObject.Path); CurrentDocument.Activate(); WordApplication.Visible=True; WordApplication.Activate(); //Here is - bringing a Word-document window to forefront in one code line ObjectAutoIt.WinSetState(DocumentName,',ObjectAutoIt.SW_MAXIMIZE); I wonder, why setting wdWindowState for ActiveWindow property in Word-VBA code isn't working. This AutoIt code does the same but in other way - and it works fine.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2018
Categories |