Run a Batch in VB

JShaper

New Member
Joined
Oct 19, 2009
Messages
19
Is there an Easier way to do this because this won't work.

I have 3 batch scripts to run different commands based on a variable.

Basically this variable could be a user server or group. I have a dsquery | DSGET that i have outputting into a text for groups. I then have a function that will read in these users and groups and determines what they are later

I have the import scripted but I don't have the batch script scripted right.

Here is my batch import script as of right now (note i will make it a function later.

Code:
Sub runbat()
Dim RetVal
var1 = """Domain Admins"""
shl = "C:\TEMP\test.bat " & var1
RetVal = Shell(shl, 1)
End Sub

I have the shl step to ensure that the shell command is as intended

I run the .bat from cmd.exe and the variable passes properly and the .txt is created when i run the vba code above i get nothing no error or text file. Any sugestions would be appreciated
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Batch Files are not allowed to run automatically in a command window in WinXP and above.

You can run them manually as you already stated.
 
Upvote 0
I can run them from a command window i can even from cmd.exe run the command

Code:
cmd.exe /c test.bat "Domain Admins"

and it will create the text file i need but no command put into VBA seems to create the text file is there anyway?

But i have solved this problem by putting the command in the batch directly into the shell after /c since it was one line it worked I may need help on how to execute a batch later. If you have any sugestions please let me know.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top