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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

zacemmel

Well-known Member
Joined
Apr 29, 2002
Messages
636
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
 

dowingc

Board Regular
Joined
Oct 27, 2002
Messages
77
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. :|
 

dowingc

Board Regular
Joined
Oct 27, 2002
Messages
77
Ah, got the shell function working sort of, I can play with it...Thanks!!
 

zacemmel

Well-known Member
Joined
Apr 29, 2002
Messages
636
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,668
Messages
5,838,680
Members
430,563
Latest member
Raeyven

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
Top