Discussion:
Runtime error "5": Invalid procedure call or argument
(too old to reply)
Roy
2003-09-12 09:15:24 UTC
Permalink
I have been getting the following error message since I upgraded to Win XP.

Runtime error "5":

Invalid 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.
Simon Wilson
2003-09-12 10:27:30 UTC
Permalink
Hi Roy,

1. AppActivate expects a string as the parameter rather than the ReturnValue
(a double) so I am surprised this ever worked.
2. You need to pass at least the first few characters of the window title so
that the window is uniquely identified. In this case you could use
"FaxHY.doc"
3. If no matching window is returned you will get Error 5.

HTH,

Simon
Is Winword actually starting?
Post by Roy
I have been getting the following error message since I upgraded to Win
XP.
Post by Roy
Invalid 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.
Simon Wilson
2003-09-12 10:48:13 UTC
Permalink
How 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.
Perhaps 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'
to activate an application.
However the Double returned by Shell is returned in a Variant so it could
be
that AppActivate is interpreting the Variant as a String rather than a
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could use
"FaxHY.doc"
3. If no matching window is returned you will get Error 5.
HTH,
Simon
Is Winword actually starting?
Post by Roy
I have been getting the following error message since I upgraded to
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Roy
2003-09-12 13:38:15 UTC
Permalink
Word is running OK.
Post by Simon Wilson
How 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.
Perhaps 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'
to activate an application.
However the Double returned by Shell is returned in a Variant so it could
be
that AppActivate is interpreting the Variant as a String rather than a
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could use
"FaxHY.doc"
3. If no matching window is returned you will get Error 5.
HTH,
Simon
Is Winword actually starting?
Post by Roy
I have been getting the following error message since I upgraded to
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Simon Wilson
2003-09-12 14:19:15 UTC
Permalink
Hi Roy,

Have you tried using the document name in the AppActivate?

Simon
Post by Roy
Word is running OK.
Post by Simon Wilson
How 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.
Perhaps 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 Wilson
to activate an application.
However the Double returned by Shell is returned in a Variant so it
could
Post by Simon Wilson
be
that AppActivate is interpreting the Variant as a String rather than a
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could use
"FaxHY.doc"
3. If no matching window is returned you will get Error 5.
HTH,
Simon
Is Winword actually starting?
Post by Roy
I have been getting the following error message since I upgraded
to
Post by Simon Wilson
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Roy
2003-09-12 15:12:34 UTC
Permalink
Hi 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 Wilson
Hi Roy,
Have you tried using the document name in the AppActivate?
Simon
Post by Roy
Word is running OK.
Post by Simon Wilson
How 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 Roy
Post by Simon Wilson
Perhaps 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 Wilson
to activate an application.
However the Double returned by Shell is returned in a Variant so it
could
Post by Simon Wilson
be
that AppActivate is interpreting the Variant as a String rather than a
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could use
"FaxHY.doc"
3. If no matching window is returned you will get Error 5.
HTH,
Simon
Is Winword actually starting?
Post by Roy
I have been getting the following error message since I upgraded
to
Post by Simon Wilson
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Simon Wilson
2003-09-13 01:53:28 UTC
Permalink
Hi 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.
Following is an example which will get you started:

Dim oWord As Object

Set oWord = CreateObject("Word.Application")
oWord.Documents.Add "FaxHY.doc"
oWord.Visible = True
Set oWord = Nothing

HTH,

Simon
Post by Roy
Hi 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 Wilson
Hi Roy,
Have you tried using the document name in the AppActivate?
Simon
Post by Roy
Word is running OK.
Post by Simon Wilson
How 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 Roy
Post by Simon Wilson
Perhaps 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 Wilson
to activate an application.
However the Double returned by Shell is returned in a Variant so it
could
Post by Simon Wilson
be
that AppActivate is interpreting the Variant as a String rather
than
Post by Roy
a
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could use
"FaxHY.doc"
3. If no matching window is returned you will get Error 5.
HTH,
Simon
Is Winword actually starting?
Post by Roy
I have been getting the following error message since I
upgraded
Post by Simon Wilson
Post by Roy
to
Post by Simon Wilson
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Roy
2003-09-15 10:06:33 UTC
Permalink
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 Wilson
Hi 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 Roy
Hi 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 Wilson
Hi Roy,
Have you tried using the document name in the AppActivate?
Simon
Post by Roy
Word is running OK.
Post by Simon Wilson
How 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 Roy
Post by Simon Wilson
Perhaps 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 Wilson
to activate an application.
However the Double returned by Shell is returned in a Variant so
it
Post by Roy
Post by Simon Wilson
Post by Roy
could
Post by Simon Wilson
be
that AppActivate is interpreting the Variant as a String rather
than
Post by Roy
a
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could
use
Post by Roy
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
Post 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 Roy
I have been getting the following error message since I
upgraded
Post by Simon Wilson
Post by Roy
to
Post by Simon Wilson
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Roy
2003-09-15 11:43:48 UTC
Permalink
Hi Simon

I tried the code you suggested and it seems to work fine.

Many Thanks

Roy
Post by Simon Wilson
Hi 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 Roy
Hi 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 Wilson
Hi Roy,
Have you tried using the document name in the AppActivate?
Simon
Post by Roy
Word is running OK.
Post by Simon Wilson
How 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 Roy
Post by Simon Wilson
Perhaps 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 Wilson
to activate an application.
However the Double returned by Shell is returned in a Variant so
it
Post by Roy
Post by Simon Wilson
Post by Roy
could
Post by Simon Wilson
be
that AppActivate is interpreting the Variant as a String rather
than
Post by Roy
a
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
Double.
You could try AppActivate CDbl(ReturnValue) to ensure that it is
interpreted
correctly.
Post by Simon Wilson
Hi 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
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
title
so
Post by Simon Wilson
that the window is uniquely identified. In this case you could
use
Post by Roy
Post by Simon Wilson
Post by Roy
Post by Simon Wilson
Post 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 Roy
I have been getting the following error message since I
upgraded
Post by Simon Wilson
Post by Roy
to
Post by Simon Wilson
Win
Post by Simon Wilson
XP.
Post by Roy
Invalid 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.
Loading...