Am I able to embed HTA code into VBScript?

333 Views Asked by At

EDITED

My company used VBScript and IE to create popups for gathering and displaying information. Now that IE is going away, we can't do this in Edge. We're looking for a way to use HTA embedded in VBScript like we did with IE. Here's what we currently have:

Function Create_Display(File_Path)
   Set objIE = CreateObject("InternetExplorer.Application")
   objIE.Navigate "about:blank"

   Win_Title = "GROUP TYPE " & MyArray(3) & " FOUND"
   objIE.Document.body.innerHTML = "<title>" & Win_Title & "</title><p class='msg'>Group Type " & MyArray(3) & " Returned for TIN: <span>" & _
   TIN & "</span></p><table border=0><tr><th>Seq#</th><th>Group Name</th><th>Group NPI</th><th>MPIN</th><th>Group Type</th><th>Group Start Date</th><th>Group Term Date</th><th>Network Start Date</th><th>Network Term Date</th><th>Network ID</th></tr><tr><td>" & List & _
   "<p class='ctrl'><input type='hidden' id='Submit' name='Submit' value='0'><input type='submit' value='OK' id='SubmitButton' onclick='document.all.Submit.value=1' autofocus></p>"

   Set Style = objIE.Document.CreateStyleSheet
   Style.AddRule "p.msg", "font-family:calibri;font-weight:bold;text-decoration:underline;color:black;"
   Style.AddRule "p.not", "font-family:calibri;color:black;"
   Style.AddRule "p.ctrl", "text-align:center;"

   objIE.Visible = True

   objIE.Document.all.Submit.Focus
            
    Do Until FormExit = "GO"
       If objIE.Document.all.Submit.Value = 1 Then
            objIE.Quit
            Exit Function
       End If
    Loop
End Function

The above code will produce a popup like this:

enter image description here

Since we will no longer be able to use objIE to interact with IE, we are looking for a way to embed HTA in the same manner. If HTA cannot be embedded, can we do something similar with WSH?

Example:

 set objShell = CreateObject("shell.application")
 objShell.Navigate "about:blank"
1

There are 1 best solutions below

7
LesFerch On

The example in the question is simple enough to be handled with MsgBox, but I'll assume you have a need to do more formatting than MsgBox provides. In which case, you can create an HTA MsgBox replacement. The example HTA below supports command line parameters for message text, dialog title, and style (CSS classname). You could extend this in many different ways, such as supporting different button options (ala MsgBox).

Example main VBScript file that calls the HTA to display a pop-up message:

Set oShell = CreateObject("WScript.Shell")

Sub HTAMsg(Msg,Title,StyleClass)
  oShell.Run ".\MsgBox.hta |" & Msg & "|" & Title & "|" & StyleClass,1,True
End Sub

FilePath = "C:\SomeDir\SomeFile.txt"
Msg = "File not found: " & FilePath
HTAMsg Msg, "Error", "S1"

MsgBox.hta:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=7">
<html>
<head>
<hta:application
  id = oHTA
  border = dialog
  innerborder = no
  caption = yes
  sysmenu = no
  maximizebutton = no
  minimizebutton = no
  scroll = no
  singleinstance = no
  showintaskbar = no
  contextmenu = no
  selection = yes
>
<style>
.S1 {color:red; background-color:LemonChiffon; font-family:Calibri}
.S2 {color:blue; background-color:LightCyan; font-family:Comic Sans MS}
.S3 {color:black; background-color:MistyRose; font-family:Consolas}
</style>
</head>
<script language="VBScript">
x = 320
y = 200
Window.ResizeTo x, y
Window.MoveTo (Screen.AvailWidth - x)/2, (Screen.AvailHeight - y)/2
CmdLine = oHTA.commandLine
Params = Split(CmdLine,"|")
MsgText = Params(1)
MsgTitle = Params(2)
MsgStyle = Params(3)

Sub window_OnLoad
  document.title = MsgTitle
  msg.InnerHTML = MsgText & "<br><br>"
  document.body.ClassName = MsgStyle
End Sub

Sub Done
  Self.Close
End Sub
</script>
<body>
  <div id=msg>
  </div>
  <input type=button value="OK" style='width:6em' onclick=Done>
</body>
</html>