Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

vbscript - passing argument from vba to vbs

I have one vb script and excel page with command button.

vb script---test.vbs

MsgBox("Hello world")

excel vba code

Private Sub CommandButton1_Click()
  Dim SFilename As String
    SFilename = "C:UsersmkamarajDesktopest.vbs" 'Change the file path

    ' Run VBScript file
    Set wshShell = CreateObject("Wscript.Shell")
    wshShell.Run """" & SFilename & """"
End Sub

When I click the button in Excel it executes the VBScript and the MessageBox is displayed. Now, I need to pass the TextBox value from Excel VBA to VBScript and that value should be displayed with that VBScript MessagBox.

How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can send Parameters to the VBScript. Have a look at the link below:

Can I pass an argument to a VBScript (vbs file launched with cscript)?

VBScript:

MsgBox("Hello " & WScript.Arguments(0))

VBA:

Private Sub CommandButton1_Click()
  Dim SFilename As String
    SFilename = "C:UsersmkamarajDesktopest.vbs " & """Something Else""" 'Change the file path

    ' Run VBScript file
    Set wshShell = CreateObject("Wscript.Shell")
    wshShell.Run """" & SFilename & """"
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...