sending HTML to Internet Explorer

kudos2u
kudos2u used Ask the Experts™
on
I have generated some html in vb that I want to open in a full instance of internet explorer. I want to do this without writing out a temorary htm file to the drive also if possible.

Kudos
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
Here is the way to send new text to a WebBrowser control:

Private Sub Command1_Click()
Dim strX As String

    strX = "<html>"
    strX = strX & "<head>"
    strX = strX & "<title>Test</title>"
    strX = strX & "</head>"
    strX = strX & "<body>"
    strX = strX & "<p>Hi.    "
    strX = strX & "</body>"
    WebBrowser1.Navigate "about:blank"
    WebBrowser1.Document.write strX
End Sub
Senior .Net Consultant
Top Expert 2016
Commented:
And here is how to do it with a full instance of IE:

Private Sub Command2_Click()
Dim objIE As Object
Dim strX As String

    Set objIE = CreateObject("InternetExplorer.Application")

    strX = "<html>"
    strX = strX & "<head>"
    strX = strX & "<title>Test</title>"
    strX = strX & "</head>"
    strX = strX & "<body>"
    strX = strX & "<p>Hi.    "
    strX = strX & "</body>"
    objIE.Visible = True
    objIE.Navigate "about:blank"
    objIE.Document.write strX
End Sub
You can also use eary binding by setting a reference to Microsoft Internet Controls, here is an early binding example that can be used in a VB6 formless application.

Further, by using CreateObject to create an instance of IE see emoreau's example, you can give a VBS script file a user interface.

Sub Main()
Dim IE As SHDocVw.InternetExplorer

Dim m$
Set IE = New SHDocVw.InternetExplorer


IE.Visible = True
IE.Navigate2 "About|Blank"


With IE
.ToolBar = True
.StatusBar = False
.FullScreen = True
.Top = 0
.Left = 0
.Navigate "about:blank"
.AddressBar = False
'wait till document loaded
Do While IE.ReadyState <> 4
DoEvents
Loop

End With
   
IE.Document.Close

m = "<html><head><title>This is a gas</Title>" + vbCrLf
m = m & "<script type=""text/vbscript"" language=""vbscript"">" + vbCrLf
m = m & "Function Release()" + vbCrLf
m = m & "DIM FRM" + vbCrLf
m = m & "SET FRM=DOCUMENT.FORMS(""fred"")" + vbCrLf
m = m & "FRM(""JIM"").Value=""1""" + vbCrLf
m = m & "End Function" + vbCrLf
m = m & "</SCRIPT>" + vbCrLf
m = m & "</head>" + vbCrLf
m = m & "<Body><form name=""fred"">" + vbCrLf
m = m & "This is an example<br>" + vbCrLf
m = m & "<input type=""hidden"" size=""0"" id=""jim"" value=""0"">" + vbCrLf
m = m & "<input type=""button"" id=""kiss"" value=""Go Now"" onclick='VBScript:release()'>" + vbCrLf
m = m & "</FORM>" + vbCrLf
m = m & "</BODY>" + vbCrLf

IE.Document.write m$
IE.Visible = True

Dim frm

Set frm = IE.Document.Forms("fred")
Dim dv
Set dv = frm("jim")


Do
    If dv.Value = "1" Then Exit Do
    DoEvents
   
Loop
IE.Quit
Set IE = Nothing


End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial