Write batch files using VBA

  • Thread starter Thread starter Anthony
  • Start date Start date
A

Anthony

Is it possible to write batch files using VBA?

If so, could you please provide a sample sub for this?


thank you
 
Anthony said:
Is it possible to write batch files using VBA?

If so, could you please provide a sample sub for this?


thank you

Contrary to Doug's take on your question, I think you may be talking
about writing out a batch file (.bat or .vbs) using VBA, so that the
batch file can then be executed. To do that, you can use the basic I/O
statements Open, Print #, and Close. In conjunction with them, you'll
want to use the FreeFile() function to get a free file number. Example
code might look like this:

'----- start of code -----
Dim intFile As Integer

intFile = FreeFile()

Open "C:\Temp\MyBatchFile.bat" For Output As #intFile
Print #intFile, "Line 1 of batch file"
Print #intFile, "Line 2 of batch file"
Close #intFile
'----- end of code -----
 

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

Back
Top