Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Shell command writes file to wrong directory

I'm calling a command line exe from within Excel 2007 using VBA. The problem
I'm having is the exe outputs a file, e.g. foobar.txt, but it always puts it
in the last directory I opened an Excel file from rather than the directory
where the exe is being called.

For example, say I open a spreadsheet in "c:\excel\worksheet.xls" and in VBA
I call an exe in "c:\test\foobar.exe". The file that foobar.exe generates
gets copied into "c:\excel" instead of "c:\test"

Anyone know what's going on and how to prevent it?

thanks,
Dustin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Shell command writes file to wrong directory

You might try using ChDrive and ChDir before Shell'ing to the exe. Either
that or use a BAT file that calls the EXE and in the BAT file use CD to
change the current directory.

ChDrive "C:\Test"
ChDir "C:\Test"
Shell "C:\Test\foobar.exe"



--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Dustin" wrote in message
...
I'm calling a command line exe from within Excel 2007 using VBA. The
problem
I'm having is the exe outputs a file, e.g. foobar.txt, but it always puts
it
in the last directory I opened an Excel file from rather than the
directory
where the exe is being called.

For example, say I open a spreadsheet in "c:\excel\worksheet.xls" and in
VBA
I call an exe in "c:\test\foobar.exe". The file that foobar.exe generates
gets copied into "c:\excel" instead of "c:\test"

Anyone know what's going on and how to prevent it?

thanks,
Dustin


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Shell command writes file to wrong directory

I think that did it, thanks!

"Chip Pearson" wrote:

You might try using ChDrive and ChDir before Shell'ing to the exe. Either
that or use a BAT file that calls the EXE and in the BAT file use CD to
change the current directory.

ChDrive "C:\Test"
ChDir "C:\Test"
Shell "C:\Test\foobar.exe"



--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Dustin" wrote in message
...
I'm calling a command line exe from within Excel 2007 using VBA. The
problem
I'm having is the exe outputs a file, e.g. foobar.txt, but it always puts
it
in the last directory I opened an Excel file from rather than the
directory
where the exe is being called.

For example, say I open a spreadsheet in "c:\excel\worksheet.xls" and in
VBA
I call an exe in "c:\test\foobar.exe". The file that foobar.exe generates
gets copied into "c:\excel" instead of "c:\test"

Anyone know what's going on and how to prevent it?

thanks,
Dustin


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
send parameters to a batch file with the shell command Marcos[_2_] Excel Programming 6 May 28th 06 07:53 PM
getting vba shell command to execute batch and save output to a file Mad Scientist Jr Excel Programming 2 April 28th 06 03:00 PM
Shell command and exe file conundrum Greg Wilson[_4_] Excel Programming 2 September 4th 04 09:24 PM
Shell Command - Net Time (Cannot create text file) Alan Excel Programming 4 August 2nd 04 06:13 AM
Copying a file with VBA (or with a SHELL command) Franck V. Excel Programming 1 September 15th 03 07:46 PM


All times are GMT +1. The time now is 01:11 AM.

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

About Us

"It's about Microsoft Excel"