NEWBIE: Trouble with simple script to change margins in Word

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Howard

NEWBIE: Trouble with simple script to change margins in Word

Post by Howard » Tue Feb 04, 2003 3:47 am

I am a newbie to Macro Scheduler and know very little about programming but I am trying to create a very basic macro which should not give me problems (but, of course it is).

I enclose the script below. First, when I run this macro from MS Word, Macro Scheduler pops up for the input. Then, it generally gets hung up and does not send the input (the new margins) to Word.

As you can see below, I ask for input, I name the variable and give the default setting. I then send that input, which should place it in the margin setting box in Word.

When I try to run this with only the first input line in the script (to test it out), it switches to Word after I enter the input, but then I manually have to mouseclick on the margin setting box (and the macro does not enter what I put into the input box.

In other words, the problem seems to be that when Macro Scheduler inexplicably switches to itself when I run the macro, the word window somehow has to be reconnected for the macro to work.

I may not beusing the correct terminology here, but I hope the problem is clear. Any tips?

Thanks.

Howard
USA
========================>
Press ALT
Send>f
Release ALT
Send>u
Input>topmargin,Please enter topmargin,1
Send Character/Text>topmargin
Press tab
Input>bottommargin,Please enter bottom margin,1
Send Character/Text>bottommargin
Press tab
Input>leftmargin,Please enter left margin,1
Send Character/Text>leftmargin
Press tab
Input>rightmargin,Please enter right margin,1
Send Character/Text>rightmargin
Press tab *8
Press enter

Lumumba

Post by Lumumba » Tue Feb 04, 2003 5:45 am

You have to get/set the focus to the window (changes I've made are in bold).

SetFocus>Microsoft Word*
Press ALT
Send>fu
Release ALT

Input>topmargin,Please enter topmargin,1
Input>bottommargin,Please enter bottom margin,1
Input>leftmargin,Please enter left margin,1
Input>rightmargin,Please enter right margin,1

SetFocus>Page Setup*
Send Character/Text>topmargin
Press tab
Send Character/Text>bottommargin
Press tab
Send Character/Text>leftmargin
Press tab
Send Character/Text>rightmargin
Press tab *8
Press enter

Howard

Doesn't work

Post by Howard » Tue Feb 04, 2003 4:07 pm

Thanks for the suggestion, but it still doesn't work. Though I run the program from MS Word, asking for input switches over to Mscheduler.

The macro then performs erratically, sometimes allowing me to input numbers, other times not, but it does not send the numbers to the dialog box.

Thanks,

Howard

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Feb 04, 2003 4:35 pm

Input will switch over to Macro Scheduler if use it's Input command.

You should always, therefore, use SetFocus before sending any keystrokes to ensure the correct application has the focus to receive those keystrokes, otherwise there is no knowing where they will end up.

You need to make sure you have the correct SetFocus statements in place. Note down the window titles that need to receive the focus and use SetFocus with these titles before sending the text.
MJT Net Support
[email protected]

Lumumba

Post by Lumumba » Tue Feb 04, 2003 4:53 pm

Just to be sure - put this at the beginning of your script.

CapsOff

Move the ALTblabla section right behind the input section and include the variables into %%. Good luck.

...

Input>rightmargin,Please enter right margin,1
Wait>1.5

SetFocus>Microsoft Word*
Press ALT
Send>fu
Release ALT

SetFocus>Page Setup*
Send Character/Text>%topmargin%
Press tab
Send Character/Text>%bottommargin%
Press tab
Send Character/Text>%leftmargin%
Press tab
Send Character/Text>%rightmargin%
Press tab *8
Press enter

Howard

still not working

Post by Howard » Wed Feb 05, 2003 1:16 am

Thanks for all the suggestions, but so far, none are working.

Here is the current state of the script (please note, setfocus did not recognize Page setup, so I used MS Word):

psOff
SetFocus>Microsoft Word*
Input>topmargin,topmargin,1
Input>bottommargin,bottommargin,1
Input>leftmargin,leftmargin,1
Input>rightmargin,rightmargin,1

SetFocus>Microsoft Word*
Press ALT
Send>fu
Release ALT
Send Character/Text>%topmargin%
Wait>1.5
Press tab
SetFocus>Microsoft Word*
Send Character/Text>%bottommargin%
Wait>1.5
Press tab
SetFocus>Microsoft Word*
Send Character/Text>%leftmargin%
Wait>1.5
Press tab
SetFocus>Microsoft Word*
Send Character/Text>%rightmargin%
Wait>1.5
Press tab *8
Press enter

I am a novice at this, but this seems like it should be straightforward to do. Is it me or is it the program?

Thanks,

Howard

Lumumba

Post by Lumumba » Wed Feb 05, 2003 8:19 am

Hi,
let's compare.
My system: NT4.0, Word97, Macro Scheduler 6.x, English
Word Window Title (new doc loaded): Microsoft Word - Document1
Page Setup Window Title: Page Setup

Check about active window title with:

Code: Select all

GetActive Window>WindowTitle,x,y
MessageModal>%WindowTitle%
a) assume psOff is a typo?!
b) if all window caption matches, the order the windows are focused should be:
&nbsp&nbsp&nbsp&nbsp1) Word Window
&nbsp&nbsp&nbsp&nbsp2) Input
&nbsp&nbsp&nbsp&nbsp3) Word Window
&nbsp&nbsp&nbsp&nbsp4) Page Setup Window (which shouldn't loose the focus as long as not aborted by the user)

c) check which field at the "page setup"-form has the focus when it pops up.

Howard

still no luck

Post by Howard » Wed Feb 05, 2003 5:50 pm

yes, that was a typo. I tried you suggestions, but still no luck.

I have Windows XP, Word 2000.

Do you have any macros that work with Word menus, allowing user input?

Unfortunately, if I can't get this simple macro to work, I am going to have to find a different macro program. But, I do appreciate your help and suggestions.

Thanks.

Howard

Lumumba

Post by Lumumba » Wed Feb 05, 2003 8:42 pm

Hi,
to be honest, it will be hard to find an equivalent to Macro Scheduler 8)
I have to work with processing 24/7 so I'm always hunting for the best way of doing something SMART not hard. I expect that you won't give up.
If I can do it - everyone can do it ...

Cause Macro Scheduler is working on your behalf (Mouse, Key, etc. ...) everything, and in this case every little detail has to be the same as you would do it yourself.

The perfect way for a NEWbie is to record the Macro with Macro Scheduler. So you can have a look at the code afterwards to get an idea what's about (my main problem in the begining was to set enough Wait(s)>). On the other hand there's always the chance that an application you wanna control with MSched won't behave as you expect it to do. But there are a bunch of ways/commands to get what you want.

So Ladies with XP&Word2K. Help Howard ...

Howard, please open the Page Setup and start this code/script afterwards from the taskbar/symbol (but don't touch anything while executed):

Code: Select all

CapsOff
Let>value=1.5
Wait>2

//focus is already on the first field (value selected): Top
Send>%value%
Press Tab
//2nd field: Bottom
Send>%value%
Press Tab
//3rd: Left
Send>%value%
Press Tab
//4th: Right
Send>%value%
//focus is still at the OK button, so you don't have to "Tab" to it, just press it.
Press Enter
I've checked it on W2K with Word2K and it worked fine!

Split your script for testing.

Script A: Call Page Setup
Script B: Check data from MSched Input
Script B: Input data on Page Setup (like my sample code)
Script C: Merge Script A+B+C to get the final script

So, train your brain :D and keep in mind the "cut and paste from the forum" issue.

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