WebBrowser.Document.All() returns "Nothing", unless... (MSHTML & WebBrowser control)



Here's the VB6 (SP6) code that simply attempts to place an image
with/In an existing <TD> element on a webpage. It works in the VB IDE
if you manually step through it; fails if you just run it.

Note:
WebBrowser is the WebBrowser control dropped onto a VB form
m_oDocument is an MSHTML.HTMLDocument

Private Sub ugh()
Dim oCell As MSHTML.HTMLTableCell
Dim oImg As MSHTML.HTMLImg

Set m_oDocument = WebBrowser.Document

Set oImg = m_oDocument.createElement("img")
oImg.src = "C:\images\widget.jpg"

Set oCell = WebBrowser.Document.All("TMainData")

If oCell.canHaveChildren Then
oCell.insertAdjacentElement "beforeEnd", oImg
End If

End Sub

This code works fine *IF* you place a breakpoint before the
"...Document.All..." function call, as well as the
"...insertAdjacentElement ..." function call. Or, if you throw up a
message box prior to calling either one of these (compiled or not).
Otherwise, they return "Nothing" with no error, and the webpage's HTML
is not updated. I've tried many variations of the code above, such as
not using the oCell variable, using the Document object to get the
element, etc.

I have ensured that the Document has been fully loaded. I've tried
using DoEvents before it as well as putting in a 30 second loop before
it, with no success. It's very frustrating and hours of search has
revealed nothing that I can find. As if this has not been a problem
for anyone else.

.



Relevant Pages

  • Re: Turn off automatic row addition?
    ... Try this macro (posted by Jay Freedman two years ago in the "TAB key appends ... Dim oCell As Cell ... Set oCell = ActiveDocument.Tables.Cell ...
    (microsoft.public.word.tables)
  • Re: Turn off automatic row addition?
    ... Microsoft Word MVP ... Dim oCell As Cell ... Set oCell = ActiveDocument.Tables.Cell ...
    (microsoft.public.word.tables)
  • Re: Turn off automatic row addition?
    ... Dim oRg As Range ... Dim oCell As Cell ... Set oCell = ActiveDocument.Tables.Cell ...
    (microsoft.public.word.tables)
  • Re: nagivating rows and columns
    ... For Each oCell In oCells ... "greg" wrote in message ... > i am trying to find a good way to nagivate through the cells. ... Set oCell = oCell.Next ...
    (microsoft.public.excel.programming)