Solved

Displaying a HTMLDocument in a WebBrowser control

Posted on 2002-03-18
12
465 Views
Last Modified: 2008-02-01
Hi,

How can one display a HTMLDocument created outside of the WebBrowser control in the control? I try the .Document property, but its read-only?

I have like:

dim a as HTMLDocument
dim b as HTMLDocument
dim c as HTMLDocument

if xyz then
  WebBrowser1.Document = a
else if zyx then
  WebBrowser1.Document = b
...
 
That kind of thing. What I also do tho is load the HTML document into a HTMLDocument object, manipulate it, then either send it straight to the print, or dhow it in a WebBrowser ( for "print preview" ).

Any ideas?

Many thankx in advance,
Mark Hewitt
0
Comment
Question by:mh2
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6876942
I think you must save the edited document and then reload
the document in your WebBrowser object...

WoK;)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6877437
Use .navigate event for each one.
Where are a, b and c stored?
0
 
LVL 3

Author Comment

by:mh2
ID: 6879625
Hi,

The actual documents are in memory, I don't want to/can't load the WebBrowser control from a file.

Heres an example:

'-------------------------------------------

' load the report template
Dim A as HTMLDocument
set A = tmp.CreateDocumentFromURL("file://c:\reports\tempalte.html")

' fill in our fields based on user input and stuff
A.all("airbase").innerText = "Cliffview A102"

' choose one of two paths, print direct or print preview
if ( bUserChoseToPreview ) then

  ' display it in a web browser to simulate "print preview"
  ' the preview will IRL popup a dialog, the form with
  ' the print button in it wont have a WebBrowser control
  ' hence the need for a generic HTMLDocument above
  set WebBrowser1.Document = A   ' fails: .document is read-only???
else
  A.execCommand "Print"     ' go straight to printer
 
end if

'-------------------------------------------

So basically, I am looking to create a print-preview mechaism after I have updated a HTMLDocument object. If there is a better way I'd be more than happy to know!

Thankx,
Mark
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6880210
I am not sure but try:
WebBrowser1.Document.body.innerhtml = A.documentelement.innerhtml
Before access WebBrowser1.Document it must be a really document in webbrowser control or the method will fails.
You could do the following

WebBrowser1.navigate "about:blank"
do while WebBrowser1.ReadyState <> READYSTATE_COMPLETE
   doevents
loop

WebBrowser1.Document.body.innerhtml = A.documentelement.innerhtml
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 120 total points
ID: 6880295
This works:

Option Explicit

Dim a As New HTMLDocument
Private Sub Form_Load()
Dim ff As Integer
ff = FreeFile
Open "c:\temp.htm" For Input As ff
a.body.innerHTML = Input(LOF(ff), 1)
Close ff
With WB1
    .Navigate "about:blank"
    Do While .ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    .Document.body.innerHTML = a.documentElement.innerHTML
End With
End Sub

Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
   
End If
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6886924
hi, any problem with that?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:mh2
ID: 6887977
Hi,

Sorry it took so long, my machine crashed and I haven't been able to work for the past 2 days or so!

It woprked perfectly, I'm feeling really stupid, such an obvious thing to do, now why didn't I think of that?? :)

Thankx again for your help,
Mark
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6888618
You are welcome.
Thanks for "A" grade!
0
 

Expert Comment

by:Buchankas
ID: 8234903
Hello guys...

I got the same question as mh2, however I haven't fully figured out Simonetti's code. I am trying to load a crude HTML code from a normal textbox to the WebBrowser Control, is tha possible?

Thanks =o)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8234920
Buchankas: did you set a reference to Microsoft HTML object lbrary in your project?
0
 

Expert Comment

by:Buchankas
ID: 8234981
Yes, I did... the problem I am facing now is that my WebBrowser1 control (WB1 in your code), doens't show the "Document.body.innerHTML" when I write "WebBrowser1" and press the dot key... it should list all properties, methods available, but it doesn't... so something is wrong...

How did you declare and set this WB1? I presume it stands for the WebBrowser1 Control, right?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8236810
Nothing is wrong and yes, you are right. WB control doesn't displays anything beyond Document property.

try this

Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
   ' change de name to your HTMLDocument variable
   set wbdoc = wb1.document
   ' and now, use the dot with wbdoc variable...
End If
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 38
VBA: Select SQL query based on a config Sheet v2 11 38
Recommendation vb6 to vb.net or others 14 109
Set email body to html using vbscript 6 24
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now