Solved

Displaying a HTMLDocument in a WebBrowser control

Posted on 2002-03-18
12
466 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

785 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