Solved

Displaying a HTMLDocument in a WebBrowser control

Posted on 2002-03-18
12
462 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now