I'm trying to figure out a way to call a VBScript
function using vba in Excel
, and then pass a value back to excel-vba. See below
VBA
within Excel
Sub RunTest()
Dim objString as String
'Begin Pseudocode
objString = Call VBScript Function Test()
'End Pseudocode
MsgBox objString `from VBS
End Sub
VBScript
Function Test
Test = "Hello World"
End Function
I know this may seem strange because I could just write the function in VBA, but we had an office patch pushed out and it completely killed the functionality of one of my macros for some reason. Strange thing is, I can run the exact same code within any other office program, just not excel. As a work around, I moved the function that crashes excel to word and I pull it using application.run, but I prefer to not have to do that, as opening a the word application to run my macro slows my process way down.
Any help is appreciated, thank You
Try syntax like:
Ok, I feel a litte dirty :)
This code has two key parts:
vbs
UsesGetObject
and the full host workbook path to re-attach to the file containing theVBA
that called theVBS
VBS
adds a value to a specific worksheet in the hostVBA
file to trigger theWorksheet_Change
event to fire, runningVBA
with the string passed from theVBS
.Step 1: Regular Excel code module
Step 2: myvbs
Step 3: Sheet code for vbs sheet in your Excel File