Hi Simon
Firstly in answer to the 3 items below:
1. I am not sure if AppActivate is necessary or if I can assume that the
newly open process will always get focus.
2. Yes I have upgraded Office as well. Changing the setting suggested
does not cure the problem.
3. We want the invoking process to terminate once word is running
correctly.
I have experimented with running other applications and have found the
following:
1. The problem does not occur with Excel even if Excel sessions are
already running. The process id is returned correctly by the Shell command
and the correct Excel session gets focus.
2. If I am not running any other word sessions and programs such as
Outlook are not running then the process id is returned correctly by the
Shell command and the Word session gets focus.
3. If either Outlook is running or another Word session is running then
an incorrect process id is returned by the Shell command and the AppActivate
call fails. The process id returned by Shell does not appear in the list of
active processes.
Roy
Post by Simon WilsonHi Roy,
1. Do you need to do the AppActivate at all? Word opens as the active
window for me without it.
2. Have you upgraded to Office XP as well as Windows XP? If so Word may be
set to use an MDI interface rather than SDI. Try changing the Tools -
Options - Windows in Taskbar setting. This is new to Office XP.
3. If all else fails try office automation instead of the shell function.
Dim oWord As Object
Set oWord = CreateObject("Word.Application")
oWord.Documents.Add "FaxHY.doc"
oWord.Visible = True
Set oWord = Nothing
HTH,
Simon
Post by RoyHi Simon
I have now but it gives the same error. If I give Microsoft Word as the
parameter to AppActivate then it works OK but randomly pass control to an
open word document and not necessarily the one I have opened.
Roy
Post by Simon WilsonHi Roy,
Have you tried using the document name in the AppActivate?
Simon
Post by RoyWord is running OK.
Post by Simon WilsonHow right you are! I should read the help more carefully. :-)
In that case it must be as someone else mentioned and Word is not
running.
Post by RoyPost by Simon WilsonPerhaps the path to Word should be double checked.
Simon
Au contraire.
The task ID returned by the Shell function can be used in place of
'title'
Post by Simon Wilsonto activate an application.
However the Double returned by Shell is returned in a Variant so
it
Post by RoyPost by Simon WilsonPost by Roycould
Post by Simon Wilsonbe
that AppActivate is interpreting the Variant as a String rather
than
Post by Roya
Post by Simon WilsonPost by RoyPost by Simon WilsonDouble.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon WilsonHi Roy,
1. AppActivate expects a string as the parameter rather than the
ReturnValue
Post by Simon Wilson(a double) so I am surprised this ever worked.
2. You need to pass at least the first few characters of the
window
use
Post by RoyPost by Simon WilsonPost by RoyPost by Simon WilsonPost by Simon Wilson"FaxHY.doc"
3. If no matching window is returned you will get Error 5.
HTH,
Simon
Is Winword actually starting?
Post by RoyI have been getting the following error message since I
upgraded
Post by Simon WilsonPost by Royto
Post by Simon WilsonWin
Post by Simon WilsonXP.
Post by RoyInvalid procedure call or argument
The line of code responsible is the AppActivate call below.
strCommand = CStr(strWinword & " FaxHY.doc")
ReturnValue = Shell(strCommand, 1)
sngTime = Timer
Do While Timer - sngTime < 10
Loop
AppActivate ReturnValue
The variable strWinword contains the full path to
winword.exe.