Execute VBScript from VBA?

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
joe.afusco,


If you are asking to run a macro from another macro, then:


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub Execute_VBScript_from_VBA()
' hiker95, 03/02/2012
' http://www.mrexcel.com/forum/showthread.php?t=618285
Call TestA
Call TestB
End Sub


Sub TestA()
MsgBox "Running/executing macro 'TestA' !"
End Sub


Sub TestB()
MsgBox "Running/executing macro 'TestB' !"
End Sub


Then run the Execute_VBScript_from_VBA macro:
 
Upvote 0
If you literally mean running a VBS script then the following worked for me:

Code:
'in Excel module
Sub Test()
Shell "Explorer.exe ""C:\Some Folder\MyVBSFile.vbs""",1
End Sub
 
Upvote 0
Yes a vbs script is what I meant. Thanks! Secondary question that might rule out doing this through a script... I assume it is possible, but do the same fso methods in vbs work in vba? Renaming, deleting, moving files, etc.
 
Upvote 0
Why explorer rather than wscript or cscript? If the reason is using the default association, more robust to use

Shell Environ("COMSPEC") & " /c start """" ""script path here""", 1
 
Upvote 0
You can access most Windows Scripting Host and VBScript objects from VBA. Add references to Microsoft Scripting Runtime and Microsoft VBScript Regular Expressions 5.5 to the VB project. There are many examples of accessing RegExp, Dinctionary and FileSystemObject objects on the web.
 
Upvote 0
Why explorer rather than wscript or cscript? If the reason is using the default association, more robust to use

Shell Environ("COMSPEC") & " /c start """" ""script path here""", 1

A mixture of lack of knowledge as regards the alternatives and also laziness since explorer worked!
Your post has gone some way to resolving the first issue but I'm probably stuck with the second :)
 
Upvote 0
So, this is going to sound pretty stupid. I've stored my script directory / file name in a string. How can I execute it from there? Can't seem to get it to work with the following suggestion:

Shell Environ("COMSPEC") & " /c start """" ""script path here""", 1
 
Upvote 0

Forum statistics

Threads
1,221,573
Messages
6,160,593
Members
451,657
Latest member
Ang24

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