Creates batch file with certain content, and another function to actually execute that batch file.
This is a modified version, originally by Dreams24 from https://vbatricksntips.com
Function ANmaBatchRun(Batchfile_Name)
' Tries to run Batch, and return 1 if success, 0 if not
Rett = 1
Dim rVal As Variant
rVal = Shell(Batchfile_Name, vbNormalFocus)
If rVal = 0 Then
Rett = 0
End If
ANmaBatchRun = Rett
End Function
Function ANmaBatchCreate(BatchFile, FileContent)
' Createes batch file with content as passed
' FileContent can be ....
' FileContent = "@echo off" & vbcrlf & "cd " & Chr(34) & appPath & Chr(34) & vbcrlf & "start " & appfile & vbcrlf & "exit" & vbcrlf & ""
' where ... appPath = "C:\Program Files (x86)\Google\Chrome\Application"
' and ... appfile = "chrome.exe"
' Original Author: Dreams24. Written for VBA Tricks and tips blog https://vbatricksntips.com
Dim fNum As Integer
fNum = FreeFile
Open BatchFile For Output As #fNum
Print #fNum, FileContent
Close #fNum
End Function
' Original version
'Creating and executing batch file is very useful way for project automation. It is very comprehensive to create complex automation. you can use batch file with excel VBA combination for several operations.
'Public Sub Create_Run_Batch_File()
' ' Author: Dreams24
' ' Written for VBA Tricks and tips blog
' ' https://vbatricksntips.com
' Dim fNum As Integer
' Dim rVal As Variant
' Dim appPath, appfile As String
' file_Name = "C:\Users\Dreams\Desktop\Test.bat"
' ' Variable to store Application path which is to be run
' appPath = "C:\Program Files (x86)\Google\Chrome\Application"
' ' Variable to Store Application .exe file name
' appfile = "chrome.exe"
' fNum = FreeFile
' ' Create batch file
' Open file_Name For Output As #fNum
' Print #fNum, "@echo off"
' ' Here chr(34) used for double quotes character as output of the string
' Print #fNum, "cd " & Chr(34) & appPath & Chr(34)
' Print #fNum, "start " & appfile
' Print #fNum, "exit"
' Close #fNum
' ' Run batch file
' rVal = Shell(file_Name, vbNormalFocus)
' ' NOTE THE BATCH FILE WILL RUN, BUT THE CODE WILL CONTINUE TO RUN.
' If rVal = 0 Then
' MsgBox "An Error Occured"
' Close #fNum
' End
' End If
'End Sub
' Tries to run Batch, and return 1 if success, 0 if not
Rett = 1
Dim rVal As Variant
rVal = Shell(Batchfile_Name, vbNormalFocus)
If rVal = 0 Then
Rett = 0
End If
ANmaBatchRun = Rett
End Function
Function ANmaBatchCreate(BatchFile, FileContent)
' Createes batch file with content as passed
' FileContent can be ....
' FileContent = "@echo off" & vbcrlf & "cd " & Chr(34) & appPath & Chr(34) & vbcrlf & "start " & appfile & vbcrlf & "exit" & vbcrlf & ""
' where ... appPath = "C:\Program Files (x86)\Google\Chrome\Application"
' and ... appfile = "chrome.exe"
' Original Author: Dreams24. Written for VBA Tricks and tips blog https://vbatricksntips.com
Dim fNum As Integer
fNum = FreeFile
Open BatchFile For Output As #fNum
Print #fNum, FileContent
Close #fNum
End Function
' Original version
'Creating and executing batch file is very useful way for project automation. It is very comprehensive to create complex automation. you can use batch file with excel VBA combination for several operations.
'Public Sub Create_Run_Batch_File()
' ' Author: Dreams24
' ' Written for VBA Tricks and tips blog
' ' https://vbatricksntips.com
' Dim fNum As Integer
' Dim rVal As Variant
' Dim appPath, appfile As String
' file_Name = "C:\Users\Dreams\Desktop\Test.bat"
' ' Variable to store Application path which is to be run
' appPath = "C:\Program Files (x86)\Google\Chrome\Application"
' ' Variable to Store Application .exe file name
' appfile = "chrome.exe"
' fNum = FreeFile
' ' Create batch file
' Open file_Name For Output As #fNum
' Print #fNum, "@echo off"
' ' Here chr(34) used for double quotes character as output of the string
' Print #fNum, "cd " & Chr(34) & appPath & Chr(34)
' Print #fNum, "start " & appfile
' Print #fNum, "exit"
' Close #fNum
' ' Run batch file
' rVal = Shell(file_Name, vbNormalFocus)
' ' NOTE THE BATCH FILE WILL RUN, BUT THE CODE WILL CONTINUE TO RUN.
' If rVal = 0 Then
' MsgBox "An Error Occured"
' Close #fNum
' End
' End If
'End Sub
BatchFile, FileContent
or
Batchfile_Name
or
Batchfile_Name
Views 89
Downloads 33
CodeID
DB ID