【问题标题】:How to make multiple inputbox in one userform using vbscript如何使用 vbscript 在一个用户窗体中制作多个输入框
【发布时间】:2021-01-19 17:59:54
【问题描述】:

我正在尝试使用 vbscript 在一个用户窗体中创建多个输入框,而不是一次显示一个输入框,我想一次显示多个输入框,然后从所有输入框中获取条目,但也无法在互联网上找到任何解决方案。 在我的代码中,第二个输入框是在从第一个输入框获取输入之后出现的,反之亦然,而是我想使用 vbscript 一次获取所有输入,而不是 vba

sInput = InputBox("Enter your name")

MsgBox ("You entered:" & sInput)

sInput1 = InputBox("Enter your Age")

MsgBox ("You entered:" & sInput1)

sInput2 = InputBox("Enter email id you want to send")
sInput3 = InputBox("Enter Subject")
sInput4 = InputBox("Enter Email Body")

【问题讨论】:

  • 既然你已经标记了vba,请尝试使用excel VBA Userforms
  • 我知道使用 vba 用户表单我可以做到,但我只想通过使用 vbscript 来做到这一点哦,我将删除 vba 标签@Gurman
  • 我认为这在 VBScript 中是不可能的。你可以在HTA though试试。
  • 你应该使用 HTA(HTML 应用程序)
  • 检查this answer,代码几乎可以满足您的需求,无论如何它允许以非常简单的方式创建VBS GUI。

标签: vbscript


【解决方案1】:

我从@omegastripes multiline_inputbox_via_hta.vbs找到了一个vbscript代码

不知道这个回答能不能给你一个思路?

dim completed

msgbox inputboxml("Enter text:", "Multiline inputbox via HTA", "Enter your name : " & vbcrlf & "Enter your Age : " & vbcrlf &_
"Enter email id you want to send : " & vbcrlf & "Enter Subject : " & vbcrlf & "Enter Email Body : " )

function inputboxml(prompt, title, defval)
    set window = createwindow()
    completed = 0
    defval = replace(replace(replace(defval, "&", "&amp;"), "<", "&lt;"), ">", "&gt;")
    with window
        with .document
            .title = title
            .body.style.background = "buttonface"
            .body.style.fontfamily = "consolas, courier new"
            .body.style.fontsize = "8pt"
            .body.innerhtml = "<div><center><nobr>" & prompt & "</nobr><br><br></center><textarea id='hta_textarea' style='font-family: consolas, courier new; width: 100%; height: 400px;'>" & defval & "</textarea><br><button id='hta_cancel' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>Cancel</button><button id='hta_ok' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>OK</button></div>"
        end with
        .resizeto 550, 550
        .moveto 100, 100
    end with
    window.hta_textarea.focus
    set window.hta_cancel.onclick = getref("hta_cancel")
    set window.hta_ok.onclick = getref("hta_ok")
    set window.document.body.onunload = getref("hta_onunload")
    do until completed > 0
        wscript.sleep 10
    loop
    select case completed
    case 1
        inputboxml = ""
    case 2
        inputboxml = ""
        window.close
    case 3
        inputboxml = window.hta_textarea.value
        window.close
    end select
end function

function createwindow()
    rem source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
    dim signature, shellwnd, proc
    on error resume next
    signature = left(createobject("Scriptlet.TypeLib").guid, 38)
    do
        set proc = createobject("WScript.Shell").exec("mshta ""about:<head><script>moveTo(-32000,-32000);</script><hta:application id=app border=dialog minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=yes innerborder=no icon=""%windir%\system32\notepad.exe""/><object id='shellwindow' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shellwindow.putproperty('" & signature & "',document.parentWindow);</script></head>""")
        do
            if proc.status > 0 then exit do
            for each shellwnd in createobject("Shell.Application").windows
                set createwindow = shellwnd.getproperty(signature)
                if err.number = 0 then exit function
                err.clear
            next
        loop
    loop
end function

sub hta_onunload
    completed = 1
end sub

sub hta_cancel
    completed = 2
end sub

sub hta_ok
    completed = 3
end sub

【讨论】:

    【解决方案2】:

    您好,我已经在 hta 中实现了我的 vbscript 代码,它运行良好我正在分享我的完整代码以供将来参考,请将其粘贴到记事本中并使用 .hta 扩展名保存记事本

    (使用 vbscript 供您参考,我正在尝试从用户那里获取输入,并使用密码保护将其存储在 excel 中,然后通过 Outlook 将该 excel 文件发送到用户提供的电子邮件 ID——请注意您的 Outlook 需要打开并在运行此代码之前运行,并请提供一些不同的 excel 路径,我已经给出了我的文件路径)

      <HEAD>
        <TITLE>Send Status of Task</TITLE>
        <hta:application
            applicationname="HTA Sample"
            scroll="yes"
            singleinstance'"yes"
            >
        </HEAD>
    
        <SCRIPT language="vbscript">
    
        Sub RunThisSubroutine
            str1 = TextBox1.Value
            str2 = TextBox2.Value
            str3 = TextBox3.Value
                str4 = TextBox4.Value
                str5 = TextBox5.Value
    
    
            msgBox str1 & ", " & str2 & ", " & str3 &"," & str4&"," & str5
    
        Set objExcel = CreateObject("Excel.Application")
        Set objWorkbook = objExcel.Workbooks.Open("C:\Users\saurabh.ad.sharma\Desktop\rrr.xlsx")
    
        objExcel.Application.Visible = True
    
        objExcel.Sheets(1).unprotect "saurabh"
        Set rg = objExcel.Sheets(1).Range("A1")
    
        lr = rg.CurrentRegion.Rows.Count
    
        With rg
            .Offset(lr, 0).Value = str1
            .Offset(lr, 1).Value = str2
    
        End With
    
    
        objExcel.ActiveWorkbook.Save 
        objExcel.Sheets(1).protect "saurabh"
        objExcel.ActiveWorkbook.Save 
        objExcel.ActiveWorkbook.Close
    
        objExcel.Application.Quit
    
    
        Set objOutl = CreateObject("Outlook.Application")
        Set objMailItem = objOutl.CreateItem(olMailItem)
    
        objMailItem.Display
        strEmailAddr  = str3
        objMailItem.Recipients.Add strEmailAddr
         objMailItem.Subject=str4
        objMailItem.Body = str5
        objMailItem.Attachments.Add "C:\Users\saurabh.ad.sharma\Desktop\rrr.xlsx"
        objMailItem.Send
        Set objMailItem = nothing
        Set objOutl = nothing
    
    
    
    
    
    
        End Sub
    
        </SCRIPT>
    
        <BODY STYLE="FONT:10 pt verdana; COLOR:black; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFCC66', EndColorStr='#FFFFFF')">
    
        Hyper Text Applications make it easy to add user inputs: <BR>
        <label for="Name     ">Name:</label>
        <input type="text" name="TextBox1" size="30"><BR><BR>
        <label for="Age">Age          :</label>
        <input type="text" name="TextBox2" size="30"><BR><BR>
        <label for="Send Email to">Send Email to:</label>
        <input type="text" name="TextBox3" size="30" ><BR><BR>
        <label for="Subject      ">Subject:</label>
        <input type="text" name="TextBox4" size="30" ><BR><BR>
        <label for="Body">Body:</label>
        <input type="text" name="TextBox5" size="30" ><BR><BR>
    
    
    
        <input id=runbutton class= "button" type="button" value="Run" name="button1" onClick="RunThisSubroutine">
    
        </BODY>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多