Discussion:
which object model..
(too old to reply)
flekso
2003-10-14 06:21:06 UTC
Permalink
which object model should one use if he needs to add an element to the local
document from within the vb editor (no script code) ?

'and what's wrong with this:

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

'?
Stefan B Rusynko
2003-10-14 10:09:05 UTC
Permalink
The programming.visual basic newsgroup has been discontinued.
--
_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
To find the best Newsgroup for FrontPage support see:
http://www.net-sites.com/sitebuilder/newsgroups.asp
_____________________________________________


"flekso" <***@email.hinet.hr> wrote in message news:O$T%***@TK2MSFTNGP10.phx.gbl...
| which object model should one use if he needs to add an element to the local
| document from within the vb editor (no script code) ?
|
| 'and what's wrong with this:
|
| 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
|
| '?
|
|
MD WebsUnlimited.com
2003-10-14 11:45:57 UTC
Permalink
Hi Flekso,

First there is only one object model per version of FP.

To insert an element at the current cursor location you'd use:

Dim iViewMode As Integer
Dim clsTxtRange As IHTMLTxtRange
Dim oParentElement As IHTMLElement

If Not FrontPage.ActiveDocument Is Nothing Then
'
' Save current view mode and insure we are in normal
'
iViewMode = FrontPage.ActivePageWindow.ViewMode
ActivePageWindow.ViewMode = fpPageViewNormal
'
' Get current insertion point (IP) and insert
'
Set clsTxtRange = ActiveDocument.selection.createRange

clsTxtRange.Text = "J-Bots are Cool Tools!"

' reset viewmode
'
ActivePageWindow.ViewMode = iViewMode

End If
'
' release the objects
'
set clsTxtRange = nothing

HTH,
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
----------------------------------------------------------------------------
--------------------
Post by flekso
which object model should one use if he needs to add an element to the local
document 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
'?
Jim Cheshire
2003-10-14 19:34:23 UTC
Permalink
Flesko,

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 flekso
which object model should one use if he needs to add an element to the local
document 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
'?
flekso
2003-10-15 10:08:56 UTC
Permalink
Post by Jim Cheshire
Flesko,
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 flekso
which object model should one use if he needs to add an element to the
local
Post by flekso
document 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
'?
thanks a lot!
MD WebsUnlimited.com
2003-10-15 11:49:34 UTC
Permalink
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 Cheshire
Flesko,
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 flekso
which object model should one use if he needs to add an element to the
local
Post by flekso
document 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
'?
Loading...