Execute Batch Files with VBA (SOLVED)

dowingc

Board Regular
Joined
Oct 27, 2002
Messages
77
Do you know of a way to have a command button trigger a DOS Batch file? I want a user to click 'Import' and excel will execute a batch file and import a predesignated filename automatically. Thanks!
This message was edited by dowingc on 2002-11-21 03:10
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this:

foo = Shell("yourfile.bat")

If this doesn't work, try the API function -- shellexecute

_________________
Questions?<a href=http://www.excelquestions.com>http://www.excelquestions.com</a>
This message was edited by zacemmel on 2002-10-28 23:32
 
Upvote 0
getting an error saying "foo" is not defined. I did a search for the syntax of shellexecute and vba help doesn't come up with anything. :|
 
Upvote 0
shellexecute isn't an Excel function. It's an API function located in shell32.dll. You need to put this into a module.
Here is the syntax:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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