SetFocus to Program and not file?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

SetFocus to Program and not file?

Post by RNIB » Tue Jul 22, 2008 1:42 pm

This is probably a real newbie question but all I'm trying to do is to create a macro that pretty much just replicates key strokes and copies data from one program to another.

This is what I have so far:

Code: Select all

Input>NumTimes, Enter Numer of Runs:,50
Let>x=0
Repeat>x
SetFocus>Microsoft Word
Wait>1
Press Ctrl
Press Page Down
Release Ctrl
Wait>2
Press Shift
Press Page Down
Release Shift
Wait>1
Press Ctrl
Send>c
Release Ctrl
Wait>1
SetFocus>EasePublisher
Wait>0.5
SetFocus>Table of Contents editor
Wait>0.2
Press Down
Wait>1
Press Enter
Wait>1
Press F6
Let>WW_TIMEOUT=90
WaitWindowOpen>HTML Edit
SetFocus>HTML Edit
Wait>1
Press Del *150
Wait>1
Press Ctrl
Send>v
Release Ctrl
Wait>1.5
Press Tab
Press Enter
Wait>1.5
SetFocus>EasePublisher
Wait>1
Press Alt
Press F4
Release Alt
Wait>1
Press Enter
Wait>2
Let>x=x+1
Until>x=NumTimes
This works absolutely fine if I just run it once but if I try and run it 2 or more times I get one of two 'errors'.

The first error is that it says that it can't find a window called Microsoft Word which is probably because the window is actually titled "name of file.doc - Microsoft Word" but as the file will constantly have a different name I've resorted to just using "Microsoft Word" and that does seem to work if it's run once.

If I add a second SetFocus>Microsoft Word right after the last Wait>2 command then I then get an 'error' which pops up in a separate window saying "Please Make A Selection".

So it seems that on the 2nd repeat the macro simply isn't finding the correct Microsoft Word window/file.

Is there a clever/better way of doing this, perhaps something like a Go to current open document in Microsoft Word instruction?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jul 22, 2008 2:03 pm

Add an asterisk to your window name.

From help for SetFocus>, WaitWindowOpen> or just about any function that deals with a window name.
If the last character of the window title specified is an asterisk (*), Macro Scheduler will first attempt to find the first window whose title matches the text entered exactly. If it cannot make an exact match it then looks at all windows and selects the first one it finds whose title contains the entered text. This solves the problem with applications such as Word or Netscape which change their titles depending on the document loaded. It is best to try to provide an exact (including case) window title to ensure the correct window is found, as many applications have multiple invisible windows with similar names. Specifying text without a trailing asterisk will force Macro Scheduler to only look for an exact match.

RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Post by RNIB » Tue Jul 22, 2008 2:55 pm

Ahh yes sorry. I meant to say that I had tried the asterisk approach but found the same problem.

Interestingly I've just tried adding the title of the document that is open in Word and that worked....almost.

I was able to run this macro around 15 times before it again popped up with the "Please Make A Selection" error

Maybe it needs longer wait commands?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jul 22, 2008 3:06 pm

Longer waits might be the solution. One trick I use is to set a variable at the top of the script... for example: Let>waittime=3
Then I set all of my suspect waits to Wait>%waittime%. This way I can easily bump all the waits up until I get success and then bump them back down until I start getting errors. The other thing is remark out the current wait lines rather than deleting them so that you have the original times as reference, some of them are probably good.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts