Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Shell function sometimes works, sometimes doesn't

I'm running the following code in Excel 2003 on Windows XP:

Dim calllms As String

calllms = "C:\LEICA\LMSASCII.EXE "
calllms = calllms & lblNewFilename.Caption + ".NA0"

taskid = Shell(calllms)

Most of the time this works, but sometimes I get runtime error 5, Invalid
procedure or function call, when the Shell function is executed. The variable
calllms evaluates to

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1 \Temp\tmpa0n.NA0"

with no spaces in the file name. If I copy this string and execute it from
the run command under Start, there are no problems whatsoever. I've tried
ShellExecute as well, as it is also inconsistent. Any ideas about what might
be the problem?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Shell function sometimes works, sometimes doesn't

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1
\Temp\tmpa0n.NA0"
Sure that's correct ? With spaces after "LOCALS~1".

Also, this file is in the temp folder. Are you sure it exists before the
call is made ?

Also, how are you getting this short name ?
With the API GetShortPathName ?

NickHK

"HC Hamaker" wrote in message
...
I'm running the following code in Excel 2003 on Windows XP:

Dim calllms As String

calllms = "C:\LEICA\LMSASCII.EXE "
calllms = calllms & lblNewFilename.Caption + ".NA0"

taskid = Shell(calllms)

Most of the time this works, but sometimes I get runtime error 5, Invalid
procedure or function call, when the Shell function is executed. The

variable
calllms evaluates to

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1

\Temp\tmpa0n.NA0"

with no spaces in the file name. If I copy this string and execute it from
the run command under Start, there are no problems whatsoever. I've tried
ShellExecute as well, as it is also inconsistent. Any ideas about what

might
be the problem?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Shell function sometimes works, sometimes doesn't

There are no spaces in the file name, including the path. The line break is
created by this forum text box.

I am sure the file exists. I create it myself. I have verified it both by
looking at Windows Explorer and by copying the value of the calllms string
during debugging, pressing the Start button, the Run..., pasting the string
in the text box in the window, and running it successfully.

I get the path for the temp directory using the statement

temppath = Environ$("TEMP")

Hope this gives you some clues. Thanks.

"NickHK" wrote:

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1

\Temp\tmpa0n.NA0"
Sure that's correct ? With spaces after "LOCALS~1".

Also, this file is in the temp folder. Are you sure it exists before the
call is made ?

Also, how are you getting this short name ?
With the API GetShortPathName ?

NickHK

"HC Hamaker" wrote in message
...
I'm running the following code in Excel 2003 on Windows XP:

Dim calllms As String

calllms = "C:\LEICA\LMSASCII.EXE "
calllms = calllms & lblNewFilename.Caption + ".NA0"

taskid = Shell(calllms)

Most of the time this works, but sometimes I get runtime error 5, Invalid
procedure or function call, when the Shell function is executed. The

variable
calllms evaluates to

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1

\Temp\tmpa0n.NA0"

with no spaces in the file name. If I copy this string and execute it from
the run command under Start, there are no problems whatsoever. I've tried
ShellExecute as well, as it is also inconsistent. Any ideas about what

might
be the problem?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Shell function sometimes works, sometimes doesn't

Upon further research, I believe the underlying cause is that the application
I'm trying to start is 16-bit program, and the Shell function will choke on
that (even though it usually doesn't). The documentation says the workaround
is to use a 32-bit application to call 16-bit application, and use the Shell
function to start the 32-bit application. Does anyone have a suggestion on
how to do that? For example, does anyone know how to call the StartRun... on
the task bar from VBA?

"HC Hamaker" wrote:

There are no spaces in the file name, including the path. The line break is
created by this forum text box.

I am sure the file exists. I create it myself. I have verified it both by
looking at Windows Explorer and by copying the value of the calllms string
during debugging, pressing the Start button, the Run..., pasting the string
in the text box in the window, and running it successfully.

I get the path for the temp directory using the statement

temppath = Environ$("TEMP")

Hope this gives you some clues. Thanks.

"NickHK" wrote:

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1

\Temp\tmpa0n.NA0"
Sure that's correct ? With spaces after "LOCALS~1".

Also, this file is in the temp folder. Are you sure it exists before the
call is made ?

Also, how are you getting this short name ?
With the API GetShortPathName ?

NickHK

"HC Hamaker" wrote in message
...
I'm running the following code in Excel 2003 on Windows XP:

Dim calllms As String

calllms = "C:\LEICA\LMSASCII.EXE "
calllms = calllms & lblNewFilename.Caption + ".NA0"

taskid = Shell(calllms)

Most of the time this works, but sometimes I get runtime error 5, Invalid
procedure or function call, when the Shell function is executed. The

variable
calllms evaluates to

"C:\LEICA\LMSASCII.EXE C:\DOCUME~1\CHAMAK~1\LOCALS~1

\Temp\tmpa0n.NA0"

with no spaces in the file name. If I copy this string and execute it from
the run command under Start, there are no problems whatsoever. I've tried
ShellExecute as well, as it is also inconsistent. Any ideas about what

might
be the problem?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Shell function sometimes works, sometimes doesn't

Would kicking off a batch file instead do the trick for you?

tbone

On Fri, 1 Jun 2007 16:18:01 -0700, HC Hamaker
wrote:

Upon further research, I believe the underlying cause is that the application
I'm trying to start is 16-bit program, and the Shell function will choke on
that (even though it usually doesn't). The documentation says the workaround
is to use a 32-bit application to call 16-bit application, and use the Shell
function to start the 32-bit application. Does anyone have a suggestion on
how to do that? For example, does anyone know how to call the StartRun... on
the task bar from VBA?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Shell function sometimes works, sometimes doesn't

After some research, I've found that using the CreateProcess() API seems to
solve the problem. Unlike ShellExecute(), it doesn't care whether the
application is 32- or 16-bit. The documentation of it notes that Windows 95
and NT have to be treated differently; for my XP application, the latter was
the proper choice.

Thanks to you folks for your interest in my problem.

"tbone" wrote:

Would kicking off a batch file instead do the trick for you?

tbone

On Fri, 1 Jun 2007 16:18:01 -0700, HC Hamaker
wrote:

Upon further research, I believe the underlying cause is that the application
I'm trying to start is 16-bit program, and the Shell function will choke on
that (even though it usually doesn't). The documentation says the workaround
is to use a 32-bit application to call 16-bit application, and use the Shell
function to start the 32-bit application. Does anyone have a suggestion on
how to do that? For example, does anyone know how to call the StartRun... on
the task bar from VBA?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell function Phil1982 Excel Programming 2 March 16th 06 12:39 AM
Shell function John Keturi Excel Programming 1 May 23rd 04 02:09 AM
Shell function II [email protected] Excel Programming 1 September 19th 03 05:55 PM
Shell function II Don Guillett[_4_] Excel Programming 1 September 19th 03 03:31 PM
Shell function David Excel Programming 0 September 19th 03 11:30 AM


All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"