run .vbs script from excel

abadilala

New Member
Joined
Sep 29, 2017
Messages
27
I have macro file and i saved it as .vbs file. Lets called it macro.vbs, and here is the location on my local C:Dekstop\macro.vbs. here is the code inside:

<code>Sub Macro3()
Sheets("vlookup").Select
Range("B5").Select
Selection.EntireColumn.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Range("B5").Select
ActiveCell.FormulaR1C1 = "Journal classification (name)"
Range("B6").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1],LW0640!R2C5:R12163C6,2,TRUE)"
Selection.AutoFill Destination:=Range("B6:B6098")
Range("B6:B6098").Select
end sub

</code>
What I want to do is, I want to call that .vbs script from my excel file. So I plan to create the button from developer in excel and call that .vbs file.
Is there a way to do it? please share!
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
The good news is that yes, you can do this although I'm not sure it's the best solution for you. Here's what you need to do:

1. Go to File>Options
2. Click on Trust Center and then Trust Center Settings...
3. Select the Macro Settings tab
4. Check the box that says Trust access to the VBA project object model then click OK and OK again
5. Open up the VBA Editor using Alt+F11
6. Select Insert>Module
7. Go to Tools>References and add a new reference to Microsoft Visual Basic for Applications Extensibility 5.3
8. Paste in the following code:

Code:
Public Sub RunExternalMacro()

Dim vbComp As VBIDE.VBComponent
Dim codeMod As VBIDE.CodeModule

Set vbComp = ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct_StdModule)
vbComp.CodeModule.AddFromFile Environ("UserProfile") & "\Desktop\Macro.vbs"

Application.Run "Macro3"

ActiveWorkbook.VBProject.VBComponents.Remove vbComp

End Sub

Running that macro should then invoke the macro you have stored in your VBS file. However, why you wouldn't just have that as a macro in the current workbook is a bit of a mystery ...

WBD
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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