Solved

Displaying a HTMLDocument in a WebBrowser control

Posted on 2002-03-18
12
468 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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