• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run .bat file from VBA

Ganesh K

New Member
Hello,

I have to edit and run a batch file on a REMOTE COMPUTER everyday. I would like know how I can run that bat file saved on a remote computer. I am able to the file if it is saved on my local machine using the Shell command:

Code:
strBatchName = "C:\1 Calls\Script.bat"
Shell strBatchName

Can you help me here?
 
If you want to run the bat file on the server from your local machine then you'll need to share the folder it is in and then give yourself permissions to that share. Then in the Vba code you use the server name or DNS alias to qualify the full path to the file. If this is a task which can simply be scheduled then you'd be better off just using some scheduling software such as Autosys rather than calling it from your local VBA code.
 
Hi Colin,

Thanks for the response. I thought of scheduling it but there is dependance and I cannot schedule it.

But you gave me some hint as to what possibly is not allowing this one to work. Will check on that part - thank you very much.

Regards,
Ganesh K
 
Hello again,

I needed to use one simple command before that cade - to change the active directory. I was using an incorrect one:

here goes the final code:

Code:
ChDrive Left(ActiveWorkbook.Path, 1)

strBatchName = "Script.bat"


Shell strBatchName

[\code]
 
m still trying to run the bat file on server; m stuck with permissions to the drive required ( guess it needs admin rights). However, I was able to run the code on some other drive; here is code:

Code:
Sub testbat()
ChDrive Left(ActiveWorkbook.Path, 1)
strBatchName = "Script.bat"
Shell strBatchName
End Sub

I was trying to get the directory and drive in the bat file but then realized it will have to be defined in the VBA as well. Not sure if it helps you but that is the code I have so far.
 
If you want to run the bat file on the server from your local machine then you'll need to share the folder it is in and then give yourself permissions to that share. Then in the Vba code you use the server name or DNS alias to qualify the full path to the file. If this is a task which can simply be scheduled then you'd be better off just using some scheduling software such as Autosys rather than calling it from your local VBA code.
Colin, can you share what the code is for your statement above? "Then in the Vba code you use the server name or DNS alias to qualify the full path to the file". Thanks
 
You can ask the IT person to deploy it in the start up scripts if it is for many computers and users. It will run at the log on.
 
You can ask the IT person to deploy it in the start up scripts if it is for many computers and users. It will run at the log on.
I was just looking for the VBA code that was suggested above to run a .bat file on a remote machine on demand from Excel.
 
@Berty

Sharing the folder and sorting out the permissions is all done manually. Then the Shell command would be like:
Code:
Shell "\\YourServer\SharedFolder\Script.bat"
 
Back
Top