将参数从 vba 传递给 vbs [英] passing argument from vba to vbs

查看:24
本文介绍了将参数从 vba 传递给 vbs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有命令按钮的 vb 脚本和 excel 页面.

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

vb 脚本---test.vbs

vb script---test.vbs

MsgBox("Hello world")

excel vba 代码

excel vba code

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

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

当我单击 Excel 中的按钮时,它会执行 VBScript 并显示 MessageBox.现在,我需要将 TextBox valueExcel VBA 传递给 VBScript 并且该值应该与该值一起显示VBScript MessagBox.

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.

我该怎么做?

推荐答案

您可以将参数发送到 VBScript.看看下面的链接:

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

我可以通过吗VBScript 的参数(用 cscript 启动的 vbs 文件)?

VBScript:

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

VBA:

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

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

这篇关于将参数从 vba 传递给 vbs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆