Run DOS command via VBA

vjs2445

New Member
Joined
Apr 6, 2009
Messages
46
HI,

I hava a utility which convert the csv file to xml.

I run via DOSS Command Prompt with following steps:

Click Start, Run and then type cmd to run DOSS, there I type

fullpathUtility.exe fullpathCSVFile.csv fullpathGenerateXMLFile.xml

I want to do it via vba using shell.

Is there any way do it or what is the syntex can somebody help me out on this?

Regards,
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Sub test()
Dim Param As String
Dim RetVal

Param = "fullpathUtility.exe fullpathCSVFile.csv fullpathGenerateXMLFile.xml"
RetVal = Shell(Param)

End Sub
 
Last edited:
Upvote 0
Hi Poolhall,

The I made it working is creating a bat file and run using shell() function. The bat file looks like following:

cd PathAllFilesLocated
fullpathUtility.exe fullpathCSVFile.csv fullpathGenerateXMLFile.xml


Is there anyway I can bypass the bat file and use the above two lines directly in shell function?

Thanks for your help and regards,
 
Upvote 0
I think if you need more than one command you need to use a batch file. But you can control that file from VBA:

Code:
Sub test()
Dim RetVal, A, fs

Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("path\to\urbatfile.bat", True)
A.writeline "cd PathAllFilesLocated"
A.writeline "fullpathUtility.exe fullpathCSVFile.csv fullpathGenerateXMLFile.xml"
A.close

RetVal = Shell("path\to\urbatfile.bat", 1)
End Sub
 
Upvote 0
I think if you need more than one command you need to use a batch file. But you can control that file from VBA:

Code:
Sub test()
Dim RetVal, A, fs

Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("path\to\urbatfile.bat", True)
A.writeline "cd PathAllFilesLocated"
A.writeline "fullpathUtility.exe fullpathCSVFile.csv fullpathGenerateXMLFile.xml"
A.close

RetVal = Shell("path\to\urbatfile.bat", 1)
End Sub


I have been looking for this for **** close to a week (off and on). Just saying THANK YOU.
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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