如何使用vbscript在一个用户窗体中创建多个输入框

时间:2017-11-20 04:56:18

标签: vbscript

我正在尝试使用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")

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

您好我已经在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>