Problem when another app activated from macro

S

Sergey Smirnov

Hello,

I'm developing some macro for MS Word and have a problem.
To reproduce it, create simple user form, add a button
control to it and several other controls, for example
textbox, checkbox and combobox. Now execute the following
apple script behind the button using MacScript function

try
tell application Finder
set wordApp to first process whose
frontmost is true
end tell
end try
tell application Finder
activate window 0
end tell
try
tell application Finder
set frontmost of wordApp to true
end tell
end try


After this you could see the follwoing strange behaviour -
all works just fine but any control on the form now
requires for its operation mouse double click instead of
single click. For example if you want to click on button,
double-click on it works just fine but single click never
works. The same is true if you want to activate textbox,
select something in the dropdown list or select checkbox.
However if you switch to some another application manually
and then switch back to Word, everything starts working
normally with single clicks. This problem occurs in both
Word X and Word 2004 but only under Mac OS 10.3. When we
try it under 10.2 everything works correctly for both
versions of Word.

Could anyone please help with this issue?

Thanks in advance,
Sergey Smirnov
 
M

matt neuburg

Sergey Smirnov said:
Hello,

I'm developing some macro for MS Word and have a problem.
To reproduce it, create simple user form, add a button
control to it and several other controls, for example
textbox, checkbox and combobox. Now execute the following
apple script behind the button using MacScript function

try
tell application Finder
set wordApp to first process whose
frontmost is true
end tell
end try
tell application Finder
activate window 0
end tell
try
tell application Finder
set frontmost of wordApp to true
end tell
end try


After this you could see the follwoing strange behaviour -
all works just fine but any control on the form now
requires for its operation mouse double click instead of
single click. For example if you want to click on button,
double-click on it works just fine but single click never
works. The same is true if you want to activate textbox,
select something in the dropdown list or select checkbox.
However if you switch to some another application manually
and then switch back to Word, everything starts working
normally with single clicks. This problem occurs in both
Word X and Word 2004 but only under Mac OS 10.3. When we
try it under 10.2 everything works correctly for both
versions of Word.

Could anyone please help with this issue?

Clearly this has something to do with the fact that you are switching to
another app and then switching back in your app. Word is somehow not
feeling really "activated" so it requires two clicks to do stuff in the
form: once to bring the form *really* to the front, another to click on
the button.

I would try throwing in a command at the end that activates the form
explicitly. You could try "activate" as well as "set frontmost". Or you
could try "show" on the form (in VBA).

I should warn you, though, that I have found VBA forms really buggy and
have given up on them. A better solution might be to write your form in
REALbasic. Its interface works great, and it speaks both VBA and
AppleScript. m.
 
S

Sergey Smirnov

Matt,

Thanks for the response. We finally have been able to
workaround this issue by activating Word not from
AppleScript but by finding Word task using VBA Tasks
object and then call Task.Activate method.

Regards,
Sergey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top