DOS batch files

R

Robert Crandal

After a workbook is closed, is it possible to run a
macro that executes a DOS BAT file? How would
I do that?
 
R

Robert Crandal

On second thought......

I think I might NOT need to run a DOS script at all.
The DOS BAT file I had in mind simply overwrites
a file, or deletes that file and replaces it with a new
file.

Therefore, I guess my question should be, how can I
replace a target file after a Workbook is closed?
 
J

James Ravenswood

On second thought......

I think I might NOT need to run a DOS script at all.
The DOS BAT file I had in mind simply overwrites
a file, or deletes that file and replaces it with a new
file.

Therefore, I guess my question should be, how can I
replace a target file after a Workbook is closed?






- Show quoted text -

Just open your Excel file from the .bat
 
R

Robert Crandal

I probably wasn't clear, so I'll reword my question:

Upon exiting a workbook, I need to run a VBA macro that
deletes and replaces a specified file (or overwrites the
contents of that file with new data). BAT files are out
of the picture now......


James Ravenswood said:
- Show quoted text -

Just open your Excel file from the .bat
 
C

Clif McIrvin

Robert Crandal said:
I probably wasn't clear, so I'll reword my question:

Upon exiting a workbook, I need to run a VBA macro that
deletes and replaces a specified file (or overwrites the
contents of that file with new data). BAT files are out
of the picture now......

Maybe. If your users would consistently / reliably use a shortcut that
invoked a .BAT script which opened the workbook and waited for the
process to complete before continuing you would have a very simple
solution. << IF >>

Does the workbook in question actually need to be closed for the
operations to take place, or are the operations happening to a different
file?

If a different file, put the VBA code in the Workbook.Close event.

If the same file, post back and either myself or someone else can help
you design code that will run after your workbook has finished exiting.
 
R

Robert Crandal

Clif McIrvin said:
Does the workbook in question actually need to be closed for the
operations to take place, or are the operations happening to a different
file?

If a different file, put the VBA code in the Workbook.Close event.

If the same file, post back and either myself or someone else can help you
design code that will run after your workbook has finished exiting.

Basically, I need to put VBA code in Workbook.Close() that
deletes a file on the C: drive named "orders.txt". Then I need
to create a new replacement file named "orders.txt" which I
will write my own data into.
 
C

Clif McIrvin

Robert Crandal said:
Basically, I need to put VBA code in Workbook.Close() that
deletes a file on the C: drive named "orders.txt". Then I need
to create a new replacement file named "orders.txt" which I
will write my own data into.

There are different tools available for doing this in VBA. I'm not at
all familiar with the FileSystem Object, but I did use the BASIC
statements such as OPEN, KILL, etc. years ago; and they are still
available in VBA.

Check the Visual Basic Language Reference in your on-board help for
syntax.

I don't have sample code at hand, but could throw together some air code
if you need it.
 
P

Peter T

Robert Crandal said:
Basically, I need to put VBA code in Workbook.Close() that
deletes a file on the C: drive named "orders.txt". Then I need
to create a new replacement file named "orders.txt" which I
will write my own data into.

VBA can easily write text files and delete files (assuming not in use) and
no problem to include in a workbook's close event. However why does that
need to be deferred until after the workbook has closed. That would mean
calling external code that runs asynchronously, monitor the workook has
closing, then do your stuff.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top