The reason stated for the run time error is correct in most cases however
there are cases where you can insert while in Code view. The code will run
in Code or Normal view provided that the cursor in those views is in the
body section. If you have it after the body it will produce the runtime code
70. It is best to switch to Design / Normal view when coding. This is shown
in the code provided earlier (iViewMode).
Your provided code corrected.
Dim app As FrontPage.Application
Dim doc As DispFPHTMLDocument
Dim ele As IHTMLElement
Set app = Application
Set doc = app.ActiveDocument
Set ele = doc.createElement("IMG") ' Permission denied (Error 70)
doc.body.innerHTML = doc.body.innerHTML & ele.outerHTML 'it doesn't get
this far
Set app = Nothing
Set doc = Nothing
Set ele = Nothing
Honestly I can not think of a single case where I would wish to use this
method. Once you have the element created you then have to apply the
attributes to it etc.
Example:
The above code will insert a tag of <img> an nothing more.
You would still need to set the src
ele.src = "myimage.gif"
If you wish to set the width and height attributes you'll need to utilize
the setAttribute method.
It is much easier to just insert the tag at the current insertion point. Use
the code I provided.
clsTxtRange.Text = "J-Bots are Cool Tools!"
Changes to:
clsTxtRange.pasteHTML = "<img src=""myPicture.gif"" width=""100px""
height=""200px"" >"
Or if you wish to insert at the end of the page as in your example code I
would use the single line
ActiveDocument.body.insertAdjacentHTML "beforeend", "<img
src=""myPicture.gif"" width=""100px"" height=""200px"" >"
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
----------------------------------------------------------------------------
--------------------
Post by Jim CheshireFlesko,
The object model you would use is the Page Object Model. The Page Object
Model (as it seems you may have already figured out) is very similar to the
IE DOM.
In the case of your code, you are getting a runtime error because you are
not in Normal view when you are calling createElement. Whenever you are
editing the HTML code programmatically, you have to be in Normal view (or
Design view in FP2003). You also need to change the reference to "e" to
"ele", but you haven't gotten that far yet! :)
You can also programmatically set the ViewMode so that you can ensure you
are in the view you need to be in.
--
Jim Cheshire
Jimco Add-ins
http://www.jimcoaddins.com
===================================
Co-author of Special Edition
Using Microsoft FrontPage 2003
Order it today!
http://sefp2003.frontpagelink.com
Post by fleksowhich object model should one use if he needs to add an element to the
local
Post by fleksodocument from within the vb editor (no script code) ?
Dim app As FrontPage.Application
Dim doc As DispFPHTMLDocument
Dim ele As IHTMLElement
Set app = Application
Set doc = app.ActiveDocument
Set ele = doc.createElement("IMG") ' Permission denied (Error 70)
doc.body.innerHTML = doc.body.innerHTML & e.outerHTML 'it doesn't get
this far
Set app = Nothing
Set doc = Nothing
Set ele = Nothing
'?