Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Run a dos batch file as soon as I exit/save the spreadsheet

I need to be able to run a dos batch file as soon as I save and exit a
spreadsheet/workbook.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Run a dos batch file as soon as I exit/save the spreadsheet

just writ down a line of code similar to following example:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
..
..
Call Shell("C:\file.bat", 1)
..
..
end sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run a dos batch file as soon as I exit/save the spreadsheet


My .bat is executed, but each command line is viewed very quickly and
none of the command lines are executed.

HELP.

Chuckles123


--
Chuckles123
------------------------------------------------------------------------
Chuckles123's Profile: http://www.excelforum.com/member.php...o&userid=14948
View this thread: http://www.excelforum.com/showthread...hreadid=384310

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run a dos batch file as soon as I exit/save the spreadsheet


Are you sure your batch file hasn't been executed

--
Nori
-----------------------------------------------------------------------
Norie's Profile: http://www.excelforum.com/member.php...fo&userid=1936
View this thread: http://www.excelforum.com/showthread.php?threadid=38431

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run a dos batch file as soon as I exit/save the spreadsheet

You can keep that command window around by using something like:

Option Explicit

Sub testme()

Dim myBatFileName As String
myBatFileName = "C:\my file.bat"
Shell Environ("comspec") & " /k " & Chr(34) & myBatFileName & Chr(34), _
vbMaximizedFocus

End Sub

Change the /k to /c to dismiss that DOS window when it's done.

And fiddle with the vbMaximizedFocus to make it what you want. (See VBA's help
for Shell to see all the options.)

Chuckles123 wrote:

My .bat is executed, but each command line is viewed very quickly and
none of the command lines are executed.

HELP.

Chuckles123

--
Chuckles123
------------------------------------------------------------------------
Chuckles123's Profile: http://www.excelforum.com/member.php...o&userid=14948
View this thread: http://www.excelforum.com/showthread...hreadid=384310


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run a dos batch file as soon as I exit/save the spreadsheet


I, with your help, am getting closer.

First, we are running W XP Pro, XCL 2002, M VB 6.3 on a network.
This application is an utility to determine if a W Scheduled Task ha
already been completed on any given day. At the time that the Shel
Function is executed, there are no Workbooks open. My DOS batch fil
is in a folder on our G: Drive; it contains about 25 command lines tha
refer to various other files stored on the same drive.

I inserted the code you recommended and ran the macro; also, I inserte
a 'PAUSE' at the end of my DOS batch file. The macro finds the correc
batch file, but the command prompt is 'C:\Documents an
Settings\myusername\My Documents'.

I would prefer not to move my DOS batch file (the G: Drive is a networ
shared drive) and I also prefer not to change the path references in th
batch file.

Is there a way to modify my macro to accommodate my situation?

Thanks for a response.
Chuckles12

--
Chuckles12
-----------------------------------------------------------------------
Chuckles123's Profile: http://www.excelforum.com/member.php...fo&userid=1494
View this thread: http://www.excelforum.com/showthread.php?threadid=38431

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run a dos batch file as soon as I exit/save the spreadsheet

Does that mean you want to change the drive and path?

If yes, then I'd include that in the .bat file:

rem If you want turn off the screenupdating
@echo off
G:
cd "G:\what ever\folder\you need"
rem rest of your .bat file after this...

======
But if you fully qualify your file names (include both the drive and folder),
then it shouldn't matter what the active drive and current folder is.

But it is sometimes easier to just change the drive and folder.

Chuckles123 wrote:

I, with your help, am getting closer.

First, we are running W XP Pro, XCL 2002, M VB 6.3 on a network.
This application is an utility to determine if a W Scheduled Task has
already been completed on any given day. At the time that the Shell
Function is executed, there are no Workbooks open. My DOS batch file
is in a folder on our G: Drive; it contains about 25 command lines that
refer to various other files stored on the same drive.

I inserted the code you recommended and ran the macro; also, I inserted
a 'PAUSE' at the end of my DOS batch file. The macro finds the correct
batch file, but the command prompt is 'C:\Documents and
Settings\myusername\My Documents'.

I would prefer not to move my DOS batch file (the G: Drive is a network
shared drive) and I also prefer not to change the path references in the
batch file.

Is there a way to modify my macro to accommodate my situation?

Thanks for a response.
Chuckles123

--
Chuckles123
------------------------------------------------------------------------
Chuckles123's Profile: http://www.excelforum.com/member.php...o&userid=14948
View this thread: http://www.excelforum.com/showthread...hreadid=384310


--

Dave Peterson
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
How do I set up a file to automatically save on exit? Brian Excel Discussion (Misc queries) 1 May 15th 10 04:34 PM
excel save file upon exit Sarah Excel Discussion (Misc queries) 2 February 9th 07 06:42 PM
save prompt for user exit, but no save prompt for batch import? lpj Excel Discussion (Misc queries) 1 February 25th 06 02:08 AM
How can I batch open a txt file in excel 2003 and save back as a . P Silzle Excel Discussion (Misc queries) 3 February 9th 05 11:44 PM
Batch Open and Save James[_27_] Excel Programming 1 September 1st 04 05:01 PM


All times are GMT +1. The time now is 06:44 PM.

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"