1

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"
Lou
  • 389
  • 3
  • 20
  • 38
  • Does this answer your question? [How to create options dialog with VbScript?](https://stackoverflow.com/questions/923503/how-to-create-options-dialog-with-vbscript) – user692942 Oct 08 '21 at 06:16
  • Does this answer your question? [Adding a GUI to VBScript](https://stackoverflow.com/q/16052534) – user692942 Nov 02 '21 at 18:41

1 Answers1

1

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>
LesFerch
  • 1,540
  • 2
  • 5
  • 21
  • 1
    I see that you actually provided an answer to the suggested duplicate.There is no MSHTA COM interface, so you can't control it from Vbscript as you can IE. Why not use the suggested Run method? It has advantages, such as keeping all the styles in one place. And if you need a return value for a button press, you can use a registry value, as discussed in the suggested duplicate. Another approach is to move ALL of your code into an HTA and drive it from the interface instead of the other way around. Barring that, I'd look into moving to C#. – LesFerch Oct 08 '21 at 13:14
  • 2
    I just saw your edited question. Given the formatting and data to be displayed, I suggest passing the data to the MsgBox HTA via a file (probably in HTML format). But, really, it looks like you would be better off doing the entire script as an HTA. – LesFerch Oct 08 '21 at 13:23
  • I did answer the suggested duplicate. I didn't see anything close to what I'm looking for in that link. If I'm understanding you correctly, since the entire code is in vbscript and I don't have the time to convert it to C#, is there any way I can pass the data from vbscript to the HTA to display it? There has to be interaction as there are more options for the user to select before the vbscript ends...so the HTA would have to go back to the vbscript. This is fairly complex and has been part of other questions that were never answered. – Lou Oct 08 '21 at 14:38
  • Macro Express Pro, the application our company uses to run end user tools that automate user interactions to improve efficiency and accuracy, does allow for HTA, so I guess I could redo this project in HTA if what I'm asking is not possible. – Lou Oct 08 '21 at 14:42
  • To do what you're asking would require creating your own interface between the calling Vbscript and the HTA that would likely involve polling every half second or so. That would be complicated and error prone. Better off rewriting the whole thing in HTA. – LesFerch Oct 08 '21 at 14:55
  • I think I've seen some web sites developed like this...they have a HUGE script in the `...` section and then whatever code is used to display information. Are you thinking like that? If so, it may take a bit of time to do, but I'll give it a try. I need to do something before my users run their macros in Macro Express Pro and they do nothing or produce errors. – Lou Nov 03 '21 at 19:30
  • No, regardless of the amount of code, a web page (or HTA) is simply interface driven. That is, when the user does something (such as clicking a button) some code may be executed. In your case, it's essentially reversed with the VBScript code controlling IE. If it's possible to flip the logic around so that the user interface drives the script(s), then you should be able to adapt your VBScript code to an HTA. – LesFerch Nov 04 '21 at 01:30