Jump to content
Macro Express Forums

How to activate MS Word reliably? Fails on multiple configurations and macro coding methods


Recommended Posts

For years, I've had problems invoking or switching to Microsoft Word, no matter what I try.

 

The symptom is that the macro will run and complete w/o error, but instead of switching to Word, the macro just takes focus from the original window, and leaves me with no window having focus, and no program seems to be active. I have to manually switch to some window to have any active.

 

I've had this problem on several configurations-- different vesions of macro express pro (MEP) and all software. (see below for details configurations)

 

Some things I've tried w/o success:

- using activate or launch, launch and activate, or window activate

- trying different settings e.g. seconds to wait or title to switch to

- trying on several versions of MEP and Word, trying reinstalls and repairs

- trying w/o other apps running, e.g. with MS Outlook shut off

 

More details: the behavior is sporadic; it fails from 60% to 95% of the time. Doesn't happen with other programs (specifically, no problem with MS outlook on one XP box, but outlook has same problem as word on another machine.)

 

behavior seen on multiple configs, e.g. Macro Express Pro, version 4.3.0.1; seen on multiple machines running XP (1 xp home edition service pack 3), seen with both MS Word 2003 and 2007.

 

Thanks for any ideas! Robert

Link to post
Share on other sites

Hi Robert and welcome to the forum. All that time using ME and this the first time you've had to resort to the forum! ;)

 

I use an old version of Word (from Office 2000) but I'd be happy to try it if you can upload a sample MEX file. Ideally a short version, with minimal dependency on variables or suppporting data.

 

I've frequently had this sort of exasperating, intermittent problem on my own XP PC, but its causes have varied quite widely. Timing issues are probably the dominant underlying cause, but (as I've reported several times over the years, here and directly to Insight) I find the Window Activate and Wait for Window Title very unreliable. I often abandon them entirely and substitute a Delay of several seconds.

 

If there's a possibility that ME Pro is not correctly detecting the 'end' of the main macro, perhaps you could instead use pixel detection to trigger the activation of Word?

 

--

Terry, East Grinstead, UK

Link to post
Share on other sites

Some things I've tried w/o success:

- using activate or launch, launch and activate, or window activate

- trying different settings e.g. seconds to wait or title to switch to

- trying on several versions of MEP and Word, trying reinstalls and repairs

- trying w/o other apps running, e.g. with MS Outlook shut off

When I'm really desperate for a particular application to gain focus (in the example I'm using Foobar2000), I do this:

Repeat Until %n[1]% Does not Equal "%n[1]%"
 If Window "foobar2000" is focused
   Repeat Exit
 End If
 Window Activate: foobar2000
End Repeat

You could generalize this so that a shared variable contains the window name, then you could simply initialize the shared variable with your desired window name and call the macro as a subroutine. You could also add a timeout, perhaps displaying a timed message if you can't focus on the desired window in the specified time.

Link to post
Share on other sites

Terry and Paul, thanks for your help! I'll try Paul's fix.

 

I've attached a sample script, which fails as described.

 

It's a 1-line script, with just a Window Activate command, with Window Title set to "Microsoft word", and all other fields left as defaulted.

 

More info on my symptom:

 

-- by "Activate" here I mean both "Activate or Launch" and "Window Activate"; they both get the symptom when activating Word.

 

-- To clarify: the symptom I see is that the macro just takes focus from the original window, and leaves me with no window having focus. I.e. on my XP box, the active window has a blue bar and keystrokes go to that app, and the inactive windows have grey top bars and don't respond to keystrokes. When the macro runs, all windows including the top window become inactive and stay that way until I manually activate a window.

 

-- Activate will elicit this symptom and be unusable for hours or days at a time. Then for some reason, activate will work for an hour or so, and then the cycle repeats.

 

-- I have a hunch the symptom is related to having MS Outlook running. However, I can't avoid Outlook: most of my clients use it and so must I.

 

 

Follow-on question for Terry: What workaround do you use in place of Activate? I don't see how delays would help- remember, the symptom I see is that the macro just takes focus from the original window, and leaves me with no window having focus. I could wait a second or an hour; no window ever takes focus.

 

Follow-on question for other readers: has anyone had Activate work reliably-- e.g. for years-- with Word 2003/2007 on XP?

 

Thanks-- Robert

demo activate bug.mxe

Link to post
Share on other sites

To be useful to others, an attached file should be an MEX file, not an MXE.

 

You create an MEX file by r-clicking the macro in ME Explore and choosing Export.

 

However, for a very simple macro such as the one-liner you've described, you could instead just include the code in your message. To do that, copy/paste into your message, in between the code tags:

 

(And reverse the process to re-recreate the macro from code you see in any post.)

 

I'm not entirely sure I understand your problem. But with the simple scenario and 1-line macro you've described, I can't reproduce it. Here is my macro:

 

<WINDOW ACTIVATE Title="Microsoft Word" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>

 

Is yours identical? (Apart from the case of 'word/Word' which shouldn't make any difference.)

 

If my Word 2000 program is running (minimised or just hidden behind other windows), when I run this macro then Word immediately gets focus.

 

What do you mean exactly by 'the original window'? Do you mean the window that is active at the time you run the 1-line macro? Any window or folder?

 

Is your macro scoped, or global?

 

How are you activating it? What happens if you run it by pressing F9 from Script Editor? Or use other activation types?

 

What happens if you add a 500 ms delay before the Activate, making it a 2-line macro?

 

--

Terry, East Grinstead, UK

Link to post
Share on other sites
To be useful to others, an attached file should be an MEX file, not an MXE.

Why do you say that? An .MXE file can be imported into a macro file just as easily as a .MEX file, can't it?

 

If we are expressing opinions, I think it makes things easier to include the text of your macro in your post so people can read what it does without having to take extra steps to import the macro first. It is easier and faster to know what is going on by seeing this:

Window Activate: Microsoft Word

instead of this:

<WINDOW ACTIVATE Title="Microsoft Word" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>

For those who don't know, 'Copy Command Text' in the context menu copies the script in text.

Link to post
Share on other sites

2 cents:

 

I like MXEs because they're smaller but there are two downsides. First when one imports an MXE the activation is blown away to conflicts with other macros. Secondly a user can have two macro files open at the same time to the sample you send is compartmentalized. IE I don't have to dirty up my everyday MEX with your macro. Seems a bit of a draw. I don't have any problem with people posting MXEs but I can understand why some would rather have MEX.

 

Snippets are fine but I often prefer an MXE or MEX because it leaves too much out. A snippet doesn't have activation, variable definitions, and many other relevant things. Personally I often skip people who put 50 lines of macro code in a snippet and ask "Why doesn't this work" because I can't be bothered to create a macro and define all the variables for them. I guess I'm just lazy;)

 

Both your argument about plaintext/code snippets are valid. Plain text hides a ton of relevant info. Code is inscrutable and requires opening MEP and creating a macro, defining vars and all that when often just seeing the method the user is applying is enough. This is why you will notice in my posts I include both the plain text and code snippets. If you catch my drift in the plain text you're done. If you need more you can copy the code snippet. And of course if it's long, there are var definitions, and other things are relevant I will include a file.

 

While I'm at it I would also like to suggest that posters not be lazy. Taking a snippet out of a huge complex macro is hard for us to spool up. I usually try to make a sample macro to illustrate my problem. In fact I make it as simple as possible and eliminate all my other cleverness so the reader can instantly see exactly what I'm on about without deciphering a bunch of irrelevant code. Also if your issue is with a program most will not have rewrite it to illustrate the issue in something like Notepad. BTW I find I often 'fix' my problem when I try to make simple examples. Often because the simple example works which means what I suspect was the problem is not. Anyway I wish more members would take the time to do the same. I'd read and answer more of their posts;)

Link to post
Share on other sites

Why do you say that? An .MXE file can be imported into a macro file just as easily as a .MEX file, can't it?

 

Agreed, I suppose it's just a strong personal preference. MEX fits in with the way I use ME Pro (opening occasional fresh MEX files; rarely using MXE files). And I was expecting an MEX, as that's what I'd suggested to Robert! But in this case it's plainly irrelevant, as Robert's already described the script and all that was needed was the exact code.

 

Anyway, let's see if I made any progress in helping him solve the actual problem ;)

 

--

Terry, East Grinstead, UK

Link to post
Share on other sites

Thanks folks. Below and attached is the failing script, in all 4 forms just to be complete... ;-)

 

<WINDOW ACTIVATE Title="Microsoft Word" Exact_Match="FALSE" Wildcards="FALSE"/>

Window Activate: Microsoft Word

 

I haven't yet tried the suggested workarounds and tests (work very busy) but will as soon as I can get a moment.

 

As before, the script is a 1-line script, with just a Window Activate command, with Window Title set to "Microsoft Word", and all other fields left as defaulted. Everything is left at the default,

 

More info on my symptoms:

 

a) If both Word and Outlook 2007 are running, this patttern usually (always?) occurs:

--a1) if Outlook currently has a message open-- e.g. outlook is pointed at my inbox-- the macro switches to outlook, and never to word

-- a2) if Outlook currently has a message open-- e.g. outlook is pointed at calendar-- the macro leaves the current window and leaves no window current, as described earlier.

 

B) If Word is running and Outlook 2007 is not, the macro currently activates word correctly (though I'm very sure I've seen the bug appear even when outlook wasn't running in the past).

 

Note that it's not an option to:

- use some other editor, or mail client, or to not run outlook constantly. (I'm a contracter and the client wouldn't allow this.)

- "disconnect" outlook 2007 from word (per Microsoft: http://support.microsoft.com/kb/933793).

 

Thanks-- Robert

demo bug.mex

demo bug.mxe

Link to post
Share on other sites

Thanks folks. Below and attached is the failing script, in all 4 forms just to be complete... ;-)

 

I haven't yet tried the suggested workarounds and tests (work very busy) but will as soon as I can get a moment.

I must say I lost interest as soon as I read that you haven't tried the suggested workarounds and tests. If you describe a problem and get specific suggestions on how to solve it, then I don't see any purpose in you seeking more help until you've tried the already suggested solutions. Since you've already failed to take the proffered advice, what on earth could anyone in this forum do further that they haven't already done?

Link to post
Share on other sites

Hear, hear.

 

What I get from this is "I can't be bothered to spend the time to try your suggestions but if you guys want to dedicate even more time giving me other suggestion I probably won't try I'd appreciate it." [snicker] At least he's polite and honest about it.

Link to post
Share on other sites

Not going to spend a lot of time here as I need to start billing some hours but I appreciate you sent a simple sample script to test. I have Office 2010 and tested it out.

 

Tested it in 1a and 1b and it would not activate. Changed to “Document 1 – Microsoft Word” and it works. Changed it to “Document 1” and it works. “- Microsoft Word” does not work. I think I found your problem…

 

I ran a simple macro to repeat with windows and record each window title to a new line. To me I have A few apps open one is Outlook, one is a mail message I’m drafting, and then I have Word open to Document 1. But when I run the macro I have 3 windows with the string “Microsoft Word” in the title. One is an exact match. “Document1 - Microsoft Word”, “Document6 - Microsoft Word”, and “Microsoft Word”. I’m guessing that MEP is activating the last one which is a hidden window which is why it doesn’t appear to do anything. This is because Word is a MDI (Multi Document Interface) that allows windows outside of the parent window. And the parent window in this case is hidden. BTW Document 6 is the email I was composing.

 

Windows in Outlook are a nightmare. Look back at my old posts on the matter. Unlike other applications there are often hidden windows and windows with the same title. They have different handles but appear the same to you and I.

 

Often Word is set as the email editor. If you disable this does the problem should go away. Probably not an option but I thought I woudl toss it out there for you.

Link to post
Share on other sites

Yikes, folks! Very sorry if I gave the impression I'm not engaged here.

 

I simply wanted to give the first respondents the macro in the formats they'd strongly requested. I also wanted to get that out there before people lost interest in the post.

 

Hear me now, believe me later: I'll try each suggestion I get, until I have one that kills this bug/behavior.

 

Re Cory's points: first, thanks for the thoughts re MDI- I agree that seems like a factor. Of course, my challenge is to identify a workaround.

 

(And as you see, we can't disable Word as editor in outlook 2007. )

Link to post
Share on other sites

Robert could you do me a favor and use the Reply button the the message you are responding to instead of the Add Reply button? Some of us use the more advanced Outline Mode to view threads and Reply keeps the conversation threads intact whereas Add Reply dumbly tacks it on the bottom.

 

The problems I had with Outlook were very difficult to get around. And given the names of the hidden windows I don't see how you're going to get around this one using MEP. ISS added a feature to get a Windows handle but no one seems to know how to use that to activate a window and ISS has never given instructions on it.

Link to post
Share on other sites

ISS added a feature to get a Windows handle but no one seems to know how to use that to activate a window and ISS has never given instructions on it.

Oh, that's easy! Try this code:

Program Launch: "notepad.exe" (Normal)
Parameters: 
Variable Set Handle %hNotepad% from a window with the title, "notepad"
Delay: 10 seconds
Window Activate: %hNotepad%

<PROGRAM LAUNCH Path="notepad.exe" Mode="\x00" Default_Path="TRUE" Wait="1" Get_Console="FALSE"/>
<VARIABLE SET HANDLE Option="\x01" Info="notepad" Partial="TRUE" Wildcards="FALSE" Destination="%hNotepad%"/>
<DELAY Flags="\x01" Time="10"/>
<WINDOW ACTIVATE Title="%hNotepad%" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>

My understanding (probably wrong!) is that a handle variable can be used anywhere where you might otherwise use a window or control name. But I don't think it helps with MDI windows. AutIt provides more granular control over MDI windows, but it's not straight-forward.

Link to post
Share on other sites

That's interesting. Thanks for the edification. I'll have to play with this some more. Also see an option to enumerate. I'll have to ponder how this could be used in cases like this. I mean if you enumerate you still have the same problem, how to decide which to activate. If we could determine which were hidden that might help the guy.

Link to post
Share on other sites

Terry and Paul, thanks for your help! I'll try Paul's fix.

 

I've attached a sample script, which fails as described.

 

It's a 1-line script, with just a Window Activate command, with Window Title set to "Microsoft word", and all other fields left as defaulted.

 

More info on my symptom:

 

-- by "Activate" here I mean both "Activate or Launch" and "Window Activate"; they both get the symptom when activating Word.

 

-- To clarify: the symptom I see is that the macro just takes focus from the original window, and leaves me with no window having focus. I.e. on my XP box, the active window has a blue bar and keystrokes go to that app, and the inactive windows have grey top bars and don't respond to keystrokes. When the macro runs, all windows including the top window become inactive and stay that way until I manually activate a window.

 

-- Activate will elicit this symptom and be unusable for hours or days at a time. Then for some reason, activate will work for an hour or so, and then the cycle repeats.

 

-- I have a hunch the symptom is related to having MS Outlook running. However, I can't avoid Outlook: most of my clients use it and so must I.

 

 

Follow-on question for Terry: What workaround do you use in place of Activate? I don't see how delays would help- remember, the symptom I see is that the macro just takes focus from the original window, and leaves me with no window having focus. I could wait a second or an hour; no window ever takes focus.

 

Follow-on question for other readers: has anyone had Activate work reliably-- e.g. for years-- with Word 2003/2007 on XP?

 

Thanks-- Robert

 

Hi I usually don't face problems in activating Word, but I faced a similar situation on one particular computer some years back. I believe it was Word 2003 on XP.

 

My workaround was to launch Word again (i.e. Program Launch, not Activate). This results in Word launching a new instance, with the side effect of Word being activated. If you close that new instance (Window Close), you should be left with whatever Word document that was already open, and it will be in the foreground. Kludgy, but it worked for me.

 

The Word executable is usually WINWORD.EXE. The path will vary. You can also launch Word with the /n switch (no document open), but you'd still need to close the new instance.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...