Sticky Posted January 28, 2008 Share Posted January 28, 2008 Hi, I'm trying to write a program that will grab the text from an open Microsoft Word window. It's not for me so to prevent errors, I wanted my program to detect if there is more than one Microsoft Word currently open. I thought of using WinList("Microsoft Word") and then going through the array, but I always get an error if there's only one window and I'm checking $windows[2][0]. Is there a way to handle this, like a try catch? Or any other ideas of how to go about this? Thanks! Link to comment Share on other sites More sharing options...
Monamo Posted January 28, 2008 Share Posted January 28, 2008 Hi, I'm trying to write a program that will grab the text from an open Microsoft Word window. It's not for me so to prevent errors, I wanted my program to detect if there is more than one Microsoft Word currently open. I thought of using WinList("Microsoft Word") and then going through the array, but I always get an error if there's only one window and I'm checking $windows[2][0]. Is there a way to handle this, like a try catch? Or any other ideas of how to go about this? Thanks! Can you post your existing search code? You should be on the right track with WinList, but we'll need to see how your search process is put together in order to troubleshoot it. - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 28, 2008 Share Posted January 28, 2008 (edited) @Sticky - I am pretty sure that you should not programmatically close Word windows in this program, especially since it is written for someone else. This code will warn the computer user if there is more than one Word window open, and then exit if the user clicks Cancel at the message box prompt: Opt("WinTitleMatchMode", 2) $wordWinds = WinList("Microsoft Word") If $wordWinds[0][0] > 1 Then $retVal = MsgBox(262144+4096+64+1, "Sticky's Word-grabber", _ "There is more than one Microsoft Word window open. "_ & @CR & "Please close all but one and click OK, or else " _ & @CR & "click Cancel.") If $retVal <> 1 Then Exit EndIf EndIf Two caveats: 1. This code has not been tested. 2. The WinList function in this script, will match all windows that have the text "Microsoft Word" in their title. Edited January 28, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 28, 2008 Share Posted January 28, 2008 I thought of using WinList("Microsoft Word") and then going through the array, but I always get an error if there's only one window and I'm checking $windows[2][0].WinList() returns the number of windows found in [0][0], so there is no reason to attempt access to [2][0]. You could just test If $avWordList[0][0] = 1. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Sticky Posted January 29, 2008 Author Share Posted January 29, 2008 Thanks guys! I got it working now! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now