Editing in the Microsoft Web Browser Control

Hi I'm trying to use the Microsoft Web Browser control in an Access 2000 application to allow users to make minor changes to HTML script before it gets dumped into Oulook and despatched...

The story so far ... ok I've managed to find out that you use the following

Me.axMWB.Navigate "C:\ODA\ADO.htm"
Me.axMWB.Document.designmode = "on"

to load a document and get get the control in edit mode ... my issues are now

1. How to insert a new line. When the user presses the Enter Key it simply moves the focus off the control ... do I have to write some come of event capture code to put in a <BR> ?  Surely there must be an easier way.  I've tried various key combinations e.g. Ctrl-enter etc but they don't seem to work

2.  How to save the document. OK if I re run the navigate method it offers to save the existing changes (along with microsoft's tags) but there must be a neater way than this.

Thanks in advance

LVL 17
Who is Participating?
edwardiiiConnect With a Mentor Commented:
Hi, Natchiket.

I've found a way to determine when someone has clicked on your WebBrowser control, and then add a blank line at that point in the HTML document being worked on with designmode = "on".

First, add the following to your General Declarations:

     Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
     Dim WithEvents wbDoc As HTMLDocument

Next, add the code below to your WebBrowser's DocumentComplete method:

     Set wbDoc = WebBrowser1.Document
Then add the following function to your project (for example, under the DocumentComplete event):

     Private Function wbDoc_onkeypress() As Boolean  
         If GetAsyncKeyState(vbkeyreturn) < 0 Then
              wbDoc.execCommand ("insertParagraph")
         End If  
    End Function

Now you should get the functionality you're looking for as regards your question # 1 above.  For more details on all the options you can use with "execCommand", see:


For more info regarding working with editable Web pages, see:

Nat seems that the region you are using for editing is not an editable area

Try in your code setting text area so that it is enabled

if you text area was called txtHtmlArea then do this

txtHtmlArea.enabled = True

You may need to hunt around in your code to find the correct place to put this.  By enabling the editable area you can go in and add whatever text you like to it.

NatchiketAuthor Commented:
Well it allows the insertion of ordinary characters just not line breaks, so does that mean that the area is editable?

I'm not familiar with the concept of text areas within the web browser control, is this something I need to check out just for allowing line breaks ?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Hi, Natchiket.

Regarding auto-saving edits to your WebBrowser control without the popup, you can use the following (for example in a command button "Save" or in the WebBrowser's BeforeNavigate2 method:

'Private Sub cmdExit_Click()
'End Sub

'Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant,
'TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    If WebBrowser1.LocationURL <> "" Then WebBrowser1.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER
'End Sub

Regarding the issue you're experiencing with using the Enter key, I notice if I have no command buttons set as default then hitting Enter in the WebBrowser control inserts a new line.  If any of my command buttons are set with Default  = True, then a new line is not inserting in the WB control.
NatchiketAuthor Commented:
thanks edwardiii, the saving aspect certainly works,

however I'm still having problems with the enter key.

I've tried removing all command buttons from the form and now when enter key is pressed, the insertion point just stays where it is, mocking me with it's unmovingness.....
NatchiketAuthor Commented:
OK have found a solution at www.lebans.com, it's pretty involved.
NatchiketAuthor Commented:
Thanks edwardiii I haven't tried your solution but it looks good, as I mentionned www.lebans.com has a solution, in fact there's a downloadable Access web editor (using the browser contol)
Many thanks for your efforts
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.