Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

Frontpage Macro Programming

News See Also Recommended Books Recommended Links Document Object Model Tutorials Recommended Papers VBA
Microsoft Articles and How-to documents Macros
 by Stephen Travis
Finding and replacing text  FrontPage SDK Tips History Humor Etc

FrontPage is programmable in VBA and you can write useful macros for it. Unfortunately Microsoft did everything it could to block FrontPage users from utilizing its VBA programmability ;-)

One notable deficiency of  FrontPage 2000-2003 (versions before 2000 did not have VBA programmability) is that there is no macro recording capability. Theoretically macros can be used to do frequently performed tasks in FrontPage.  But details are not trivial and very difficult to implement without good knowledge of both VBA, Javascript and DOM.

For example there is a capability to control search from macros: .  Sounds great but the only example of xml representation of the query that controls behavior of the search module is the following:

 strQuery = "<?xml version=""1.0""?>" & _
"<fpquery version=""1.0"">" & _
"<find tag=""b"">" & _
"<rule type=""insideTag"" tag=""td"" />" & _
"</find>" & _
"<replace type=""changeTag"" tag=""i"" />" & _
"</fpquery>"

Microsoft does not provide any additional information other then this one example. If we try to search Frontpage 2003 help we will get the same example

The following example searches for TD elements in the current selection and adds the align attribute with a value of "center."

Dim objSearch As SearchInfo
Dim objRange As IHTMLTxtRange
Dim blnMatches As Boolean
Dim strQuery As String

strQuery = "<?xml version=""1.0""?><fpquery version=""1.0"">" & _
    "<find tag=""td""><rule type=""insideTag"" tag=""table"" />" & _
    "</find><replace type=""setAttribute"" attribute=""align"" " & _
    "value=""center""/></fpquery>"

Set objRange = ActiveDocument.selection.createRange
Set objSearch = Application.CreateSearchInfo

objSearch.QueryContents = strQuery
blnMatches = Application.ActiveDocument.Find(objSearch, Nothing, objRange)
If blnMatches = True Then objRange.Select

Only after a lot of digging you understand that query can be saved from the FrontPage menu and can be pasted into the macro.  Actually just this capability can be used instead of writing macros. But let's return to the macro. The code above simply does not work.

Still you can write code in Frontpage's Visual Basic Editor (Alt-F11 or  Tools/Macro/Visual Basic Editor). Goof luck. Open the FrontPage Visual Basic Editor. Once inside the VBE, you can begin to write your code. As with other Office applications  you can add additional code modules, forms, and even classes to your macro project. However, if you plan to share any of the macros, you will likely want to create an add-in. For more information on add-ins, see About Add-ins.

Macros are stored in the file called Microsoft FrontPage.fpm in the FrontPage macros folder. 

On computer running Microsoft Windows 2000 and 2003, this is usually

 C:\Documents and Settings\[user name]\Application Data\Microsoft\FrontPage\Macros.

It it closed when Frontpage is closed so you can export it to other computers.

Here is a useful macro that works and that demonstrates how to insert text:

'   navigationTree -  Indented List from FrontPage Navigation
'   Copyright (C) 2002  Stephen C. Travis
'
'   This program is free software; you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation; either version 2 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program; if not, write to the Free Software
'   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'   or visit their website at http://www.fsf.org/licenses/gpl.txt
'
Dim myHTML As String
Sub navigationTree()
If Not FrontPage.ActiveDocument Is Nothing Then
If FrontPage.ActivePageWindow.ViewMode = fpPageViewNormal Then
    Dim thisNode As NavigationNode
    Set thisNode = ActiveWeb.HomeNavigationNode
    myHTML = "<ul>"
    Call getChildren(thisNode)
    myHTML = myHTML & "</ul>"
    Set myRange = ActiveDocument.selection.createRange
    myRange.collapse (True)
    myRange.pasteHTML (myHTML)
End If
End If
End Sub
Private Sub getChildren(thisNode)
    myHTML = myHTML & "<li>"
    myHTML = myHTML & "<a href=""" & MakeRel(ActiveDocument, thisNode.Url) & """>" & thisNode.File.Title & "</a>"
    For i = 0 To thisNode.Children.count - 1
        myHTML = myHTML & "<ul>"
        getChildren (thisNode.Children(i))
        myHTML = myHTML & "</ul>"
    Next
    myHTML = myHTML & "</li>"
End Sub

Below in another useful (and working) sample:  Save All command - a command that saves all the open pages in Page view - to your File menu:

Sub Save_All() 'Name of the macro
  'Checks that the document is in Page view in FrontPage
  'And that at least one page is open
  If (Application.ActiveWebWindow.ViewMode = fpWebViewPage _
      And ActiveWebWindow.PageWindows.Count > 0) Then
      Dim activePage, page As PageWindow 'Declare variables 
      'Set the variable ActivePage to the
      'current active page 
      Set activePage = ActivePageWindow
      'Loop through all open pages
      For Each page In ActiveWebWindow.PageWindows
          page.Activate
          'Click the Save button for each page
          CommandBars("Add Command").Controls("&File"). _
            Controls("&Save").Execute 
      Next
      'Display the page you were working on when
      'the Save All command was clicked
      activePage.Activate
  End If
End Sub
  1. In FrontPage, click Customize on the Tools menu.
  2. Click the Commands tab, and then select Macros in the Categories list.
  3. Drag and drop the entry Custom Menu Item from the Commands list to the File menu beneath the Save command.
  4. Click Modify Selection, change the name to Save A&ll, and then press ENTER. Note  The ampersand in the word All makes the first "L" a keyboard shortcut. After the command is added to the File menu, you can press ALT+L to save all open pages.
  5. Click Modify Selection again, and then choose Assign Macro.
  6. Choose Save_All from the list, and then click OK.
  7. Click Close.

The Save All command is added to the File menu.

Add-ins are supplemental programs that extend the capabilities of Microsoft FrontPage by adding custom commands and specialized features. You can obtain add-ins from the Microsoft Office Online Web site, third-party vendors, or you can write your own custom add-in programs by using Microsoft Visual Basic for Applications.

To conserve memory and increase the speed of FrontPage, it's a good idea to unload add-in programs you don't use often. When you unload an add-in, its features and commands are removed from FrontPage, but the add-in file itself remains on your computer for easy reloading.

Developers can use Component Object Model (COM)  add-ins, which provide additional functionality in a variety of programming languages, including Microsoft Visual Basic, Microsoft Visual C++, and Microsoft Visual J++. As a developer, you'll find information about designing COM add-ins in Visual Basic Help. While you are developing and testing, you can load or unload a COM add-in in FrontPage before you have a working installation program for your add-in.

Note  Do not confuse add-ins with plug-ins. A plug-in is one of a set of software modules that integrate into Web browsers to offer a range of interactive and multimedia capabilities.

Security  Security vulnerabilities in external files or controls may extend to Web pages that use those items. For example, external style sheets (files with a .css extension), script files (files with a .js extension), custom ASP.NET controls, or other items, may pose a security risk. Be sure your style sheets, add-ins, themes, executables, scripts, controls, or other files come from trusted sources.


Notes:
  • This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Some amount of grammar and spelling errors should be expected.
  • The site contain some broken links as it develops like a living tree... Please try to use Google, Open directory, etc. to find a replacement link (see HOWTO search the WEB for details). We would appreciate if you can mail us a correct link.
Google Search
Open directory

Research Index


Old News ;-)

http://msdn.microsoft.com/office/default.aspx?pull=/library/en-us/odc_fp2003_ta/html/odc_fpWorkingWithHTMLProgrammatically.asp

1.1.1  Accessing the Position of the Insertion Point

Accessing specific elements is relatively simple. However, usually you want to access the element that is at the position of the insertion point. You may want to access the text and HTML elements that are selected or perhaps just insert text or HTML into the page without replacing any existing text. There are two ways to do this. One way uses the activeElement property, and the other uses an IHTMLSelectionObject object.

1.1.1.1  Accessing the active element

Sometimes you might want to access the currently selected element or the element that is at the position of the insertion point. To do this, you use the activeElement property of the FPHTMLDocument or IHTMLDocument object. The activeElement property returns an IHTMLElement object. The following example uses the activeElement property to create an object variable that accesses the element at the insertion point.

Dim objElement As IHTMLElement
Set objElement = ActiveDocument.activeElement

The previous example uses an IHTMLElement object to store a pointer to the active element. However, sometimes you might want to use the exact type of object. In this case you need to know the type of the active element. To do this, you can use the tagName property to return a String that contains the name of the tag. Then you need to determine which FPHTML object corresponds to that element. The following example shows a Select statement that sets the object variable based on the value of the tagName property.

Dim strTagName As String
strTagName = ActiveDocument.activeElement.TagName
Select Case LCase(strTagName)
    Case "body"
        Dim objBody As FPHTMLBody
        Set objBody = ActiveDocument.activeElement
    Case "p"
        Dim objP As FPHTMLParaElement
        Set objP = ActiveDocument.activeElement
    Case "div"
        Dim objDiv As FPHTMLDivElement
        Set objDiv = ActiveDocument.activeElement
    Case "span"
        Dim objSpan As FPHTMLSpanElement
        Set objSpan = ActiveDocument.activeElement
    Case Else
        Dim objElement As IHTMLElement
        Set objElement = ActiveDocument.activeElement
End Select

1.1.1.2  Accessing selected text and HTML

To access the selected text or the position of the insertion point, use the createRange method of the IHTMLSelectionObject object to create an IHTMLTxtRange object. To access the IHTMLSelectionObject object for a document, use the selection property of the FPHTMLDocument object.

The following example creates an IHTMLTxtRange object with the currently selected text. If no text is selected, the example accesses the position of the insertion point.

Dim objSelection As IHTMLTxtRange
Set objSelection = ActiveDocument.Selection.createRange

You can also create an IHTMLTxtRange object by using the createTextRange method of the IHTMLBodyElement or FPHTMLBody object. This approach places the entire body of the page into the text range.

Note   You can access the createTextRange method from the FPHTMLButtonElement, IHTMLButtonElement, FPHTMLInputButtonElement, IHTMLInputButtonElement, FPHTMLInputHiddenElement, IHTMLInputHiddenElement, FPHTMLInputTextElement, IHTMLInputTextElement, FPHTMLTextAreaElement, and IHTMLTextAreaElement objects; however, doing so doesn't have an effective use in this case, so this article doesn't discuss the createTextRange method in relation to these objects.

1.1.1.3  Inserting text at the insertion point

After you create a text range with the selection, you can insert text or HTML at the location of the insertion point and replace the current selection with text or HTML.

You use the text property to insert text at the insertion point, as shown in the following example.

Dim objSelection As IHTMLTxtRange
Set objSelection = ActiveDocument.Selection.createRange
objSelection.Text = "The quick red fox jumped over the lazy brown dog."

1.1.1.4  Inserting HTML at the insertion point

If you use the text property to insert HTML, FrontPage converts the tags and special symbols to their HTML equivalents. Therefore, to insert HTML into a page, use the pasteHTML method of the IHTMLTxtRange object, as shown in the following example.

Dim objSelection As IHTMLTxtRange
Set objSelection = ActiveDocument.Selection.createRange
objSelection.pasteHTML "<b>The quick red fox jumped over the lazy brown dog.</b>"

The IHTMLTxtRange object includes an htmlText property that you can use to read the selected HTML and text. However, the htmlText property is read-only; therefore, you can't use it to replace the selected HTML. In this case, use the htmlText property to read the selected text and HTML and the pasteHTML method to replace the selected text and HTML with HTML code. The following example shows how you might do this.

Dim objSelection As IHTMLTxtRange
Set objSelection = ActiveDocument.Selection.createRange
objSelection.pasteHTML "<div>" & objSelection.htmlText & "</div>"

Note   The preceding code adds a <div> tag around the currently selected text. You should know and understand the HTML specification and HTML block elements to ensure the VBA code actually generates valid HTML. For example, adding only a table cell without the corresponding table row and table tags in the middle of a paragraph generates invalid HTML.

1.1.1.5  Collapsing a text range

Sometimes a user might have selected text, but the code that runs assumes that the user has no text selected. If the code that you need to write requires that the user has no text selected (for example, if you are inserting text or code that replaces selected text or code), you can use the collapse method to collapse the range. The collapse method has an optional Boolean parameter named start that indicates whether the range collapses to the start of the range or the end of the range. The default value is True, which indicates that the range collapses at the beginning of the range; a value of False indicates that the range collapses at the end of the range. The following example uses the collapse method to collapse the range at the end of the selected range and then inserts HTML code.

Dim objSelection As IHTMLTxtRange
Set objSelection = ActiveDocument.Selection.createRange
objSelection.collapse False
objSelection.pasteHTML "<div>The quick red fox jumped over the lazy brown dog.</div>"

1.1.2  Inserting Text and HTML into a Page

In addition to using the IHTMLTxtRange object to insert text and HTML code, you can also use the insertAdjacentText and insertAdjacentHTML methods. The insertAdjacentText and insertAdjacentHTML methods are members of the IHTMLElement object and therefore of most IHTML and FPHTML objects. When you have a handle to the appropriate object, you can use the insertAdjacentText or insertAdjacentHTML method to insert text or HTML into the document.

Both the insertAdjacentText and insertAdjacentHTML methods have a where parameter that takes a string and indicates whether the text or HTML is inserted before or after the opening or closing tag for the element. The possible values are "beforeBegin", "afterBegin", "beforeEnd", and "afterEnd". The following example inserts HTML before the closing tag if the active element is the BODY element and pastes it after the closing tag for all other elements.

Dim objElement As IHTMLElement
Dim strTagName As String
Set objElement = ActiveDocument.activeElement
strTagName = objElement.TagName
Select Case strTagName
    Case "body"
        objElement.insertAdjacentHTML where:="beforeEnd", _
            HTML:="<div>The quick red fox jumped over the lazy brown dog.</div>"
    Case Else
        objElement.insertAdjacentHTML where:="afterEnd", _
            HTML:="<div>The quick red fox jumped over the lazy brown dog.</div>"
End Select

1.1.3  Programmatically Selecting Text and Code

At times you may want to programmatically select text and code. You can do this using the select method of the IHTMLTxtRange object. Regardless of whether any text or code is selected, you can specify the element to select by using the moveToElementText method of the IHTMLTxtRange object, or you can select a specified range of text and code by using the move, moveEnd, or moveStart methods of the IHTMLTxtRange object.

The following example uses the moveToElementText and select methods to select the active element and the text it contains. If the selection spans several elements, the active element is the element that contains all other selected elements.

Dim objRange As IHTMLTxtRange
Dim objElement As IHTMLElement

Set objRange = ActiveDocument.Selection.createRange
Set objElement = ActiveDocument.activeElement

objRange.moveToElementText objElement
objRange.Select

1.1.4  Inserting META Data, Styles, and Scripts

As mentioned previously, the HEAD element of a Web page doesn't have an accessor property that you can use to access it and all child elements. There is also no corresponding FPHTML or IHTML object that you can use to access elements that are typically in the HEAD section of a Web page. To access some child elements for the HEAD element, such as the TITLE element, you can use the corresponding property of the FPHTMLDocument object, such as the title property.

Sometimes you might need to insert content into the HEAD section of a Web page, such as scripts, META data, and styles; for this reason you may need to access the HEAD element. To do this, you can use the method shown previously and create an IHTMLElement object variable, as shown in the following example.

Dim objHead As IHTMLElement 
Set objHead = ActiveDocument.all.tags("head").Item(0)

When you have access to the HEAD element, you can use the all method (as described previously) to access the child META, STYLE, and SCRIPT elements or use the InsertAdjacentHTML method to insert new elements into the HEAD section of a Web page. For example, you might need to add META data or insert a SCRIPT element. For more information and code examples, see Accessing Scripts and Adding Styles to Specified Elements.

[Dec 7, 2004] Automating Repetitive Tasks in FrontPage 2003

Do you ever find yourself performing the same steps over and over again? Perhaps you publish the same Web site to several locations and find yourself repeatedly typing the Web addresses into the Publish dialog box every time you need to publish the site. Or perhaps you want to add a reference to an external style sheet to every page in your Web site and don't want to open every page to paste the necessary HTML. Macros can help.

Macros allow you to automate repetitive tasks. If you've worked with other Microsoft® Office applications, you've probably worked with macros. In fact, several Office applications have a macro recorder that you can use to create macros for those applications. Although you can't record macros in FrontPage, you can still create macros to automate your tasks, and you can create some powerful macros. With a little instruction, you can begin to develop your own collection of macros.

[Nov 30, 2000] EDITING ASP FILES WITH MICROSOFT FRONTPAGE 2000

Did you know that you could safely edit Active Server Pages (ASP) files in the Microsoft FrontPage 2000 Web site creation and management tool? New and improved handling of ASP in FrontPage 2000, combined with a few basic rules for implementing ASP, allows developers to feel comfortable letting users edit pages that include ASP code. This article describes how FrontPage determines whether to display pages containing ASP code in Normal (WYSIWYG--what you see is what you get) View or HTML View, and describes how to create ASP code that allows users to safely edit the Web pages containing the ASP code in Normal View.

   Product Home Page for Microsoft FrontPage
   Product Overview of Microsoft FrontPage 2000
   Free Downloads & Resources for Microsoft FrontPage Users
   Online Support for Microsoft FrontPage
   Publishing A Web Site with Microsoft FrontPage
   Newsgroups for Microsoft FrontPage
   Training & Certification for Microsoft FrontPage
   Books for Microsoft FrontPage
   Shop for Microsoft FrontPage 2000

Useful Shortcut Keys in FrontPage 2000

CONTROL WEB PAGE DEFAULT SETTINGS
As users of Microsoft Word are probably aware, every time you create a new document, Word bases that document on a template called Normal.dot. This template includes such information as the default font Word uses and the standard margins for pages. What you may not be aware of, however, is that Microsoft FrontPage uses a similar template whenever you create a new HTML document. By modifying this template, you can control many of the default settings on your HTML pages. In this article, you can see where FrontPage stores its template and how you can edit it:

Position and Layer Graphics and Text—Down to the Pixel—with FrontPage 2000

Using new positioning and layering tools in Microsoft FrontPage 2000, you can now place elements on your Web pages exactly where you want them. These new tools enable you to layer Web objects on top of one another, group them together as a unit, position graphics and text by setting precise pixel coordinates, wrap text around an image or text block, and more.

USEFUL SHORTCUT KEYS IN FRONTPAGE 2000
Do you find that using the keyboard is sometimes quicker than using your mouse? Shortcut keys can help you bypass menus and carry out commands directly. You can use shortcut keys in many ways with FrontPage, from accessing commands and toolbar buttons to outlining and editing information. Shortcut keys are sometimes listed next to the command name on menus. For more details, please go to:
http://officeupdate.microsoft.com/2000/focus/articles/FrontPageKeys.htm

THE JAVASCRIPT SOURCE TIP: IMAGE SLIDE SHOW
When you cut and paste this script in HTML view it will enable you to rotate a series of images in a page as a slideshow. You can customize the images and the time between each image. This script works best if all the images are the same dimension! Learn more at:
http://javascript.internet.com/miscellaneous/image-slideshow.html

 Recommended Links

Microsoft Resources

General

Groups

Microsoft Articles and How-to documents

See vbafp4.chm and vbafpom4.chm files for reference topics covering all FrontPage object model language elements, as well as topics such as “Creating Web Sites Programmatically.” The default installation path for these files is C:\Program Files\Microsoft Office\Office\1033.

More Support & Troubleshooting results  Technical Resources SDKs, resource kits, reference libraries, script centers, white papers, technical articles, product documentation...


FrontPage Publishing with Visual Basic for Applications (Microsoft FrontPage 2002 Technical Articles)

Visual Basic (VBA): Securing Microsoft Office Documents

This chapter discusses how to preserve the integrity of code in your solution by restricting access to the code.
http://www.microsoft.com/technet/prodtechnol/office/office2000/proddocs/opg/part4/ch17.asp 

Macros by Stephen C. Travis

FrontPage Macros by Stephen C. Travis

All Files - create a table at the cursor location containing a list of all files in the web and their properties (similar to the 'All Files' report).
Sort Table - sorts a table in Normal View on the column and beginning in the row that the cursor is located.
Breadcrumb Trail - creates a breadcrumb trail from the FrontPage navigation structure.
Outline - automatically numbering heading tags (eg. 1.1.2 for an H3 tag).
Navigation Tree - creates an indented list from the FrontPage navigation structure.
Screen Tips - creates a <span> tag and title attribute for selected text.
css Position - moves an object to the document body and places it inside an absolute positioned <div> tag (Used to change your page from HTML layout to CSS2 layout).
Make VBScript - convert the HTML on a page to VBScript Document.Write statements.

Microsoft FrontPage SDK

Two SDK are available: FrontPage 200 SDK and FrontPage 2002 SDK.

Download details FrontPage 2002 Software Development Kit (SDK)

Microsoft FrontPage 2000

Summary: MSDN Library - Microsoft Office 2000 Developer Object Model Guide. Excerpt: Microsoft Office 2000 Developer Object Model Guide    Microsoft FrontPage 2000 Default location:   \Program Files\Microsoft Office\Office Source (Type Library) The Microsoft

FrontPage Interactions

http:// msdn.microsoft.com / library / officedev / fp2ksdk / frontpageinteractions.htm

Summary: MSDN Library - Office Developer Documentation - Front Page 2000 SDK. Excerpt: FrontPage Interactions Wizards communicate with FrontPage using the FrontPage Visual Basic Object Model described in the FrontPage Visual Basic Help.

The FrontPage Editor Interface

Summary: MSDN Library - Office Developer Documentation - FrontPage 98. Excerpt: The FrontPage Editor Interface The FrontPage Editor is a WYSIWYG web page editor for HTML documents. Web pages are stored in .htm or .html files on the web server.

The FrontPage To Do List Interface

Summary: MSDN Library - Office Developer Documentation - FrontPage 98. Excerpt: The FrontPage To Do List Interface The FrontPage To Do List is a flexible grid-like object that manages and displays a list of tasks to be performed on the web currently opened by the FrontPage Explor

Web Workshop - FrontPage: Creating Page Backgrounds and Watermarks

Summary: Creating page backgrounds and watermarks in Microsoft FrontPage

Web Workshop - FrontPage: Establish Passwords that Protect

Summary: Use FrontPage to establish passwords that protect

Web Workshop - FrontPage: Designating a Custom Form Confirmation Page

Summary: Designating a custom form confirmation page in FrontPage


Tutorials

 Other tutorials

 

Automating Repetitive Tasks in FrontPage 2003

In FrontPage 2003, FrontPage 2002, and FrontPage 2000, you can search for and replace text in HTML pages in two ways. One way is by using the SearchInfo object, which was added in FrontPage 2003. The other way is to use the IHTMLTxtRange object.

Using the SearchInfo object, you can create customized, conditional searches that look for code in specific instances. For example, you can replace all B elements with I elements inside TD elements only. To do this, you use a query string that adheres to a defined XML schema. You can also specify a query string that finds and replaces text by using a regular expression. The first example below shows how to use the SearchInfo object. For more information, see Extending Find and Replace for Microsoft Office FrontPage 2003.

In versions prior to FrontPage 2003, you can use the IHTMLTxtRange object to perform full text search and replace. The FindInFrontPage function in the second example below uses the findText method of the IHTMLTxtRange object to locate an instance of the specified string in the specified page, and then either inserts the string or replaces the specified string with another string. The function returns a Boolean representing whether the function found the search string and successfully added the text.

The objects used in these examples are as follows:

Finding and Replacing Text Example 1

Sub QueryContents()
    Dim objSearch As SearchInfo
    Dim objRange As IHTMLTxtRange
    Dim objLimits As IHTMLTxtRange
    Dim strQuery As String
    Dim blnFoundMatch As Boolean

    'Create a query to find a TD element and
    'add an align attribute to the tag.
    strQuery = "<?xml version=""1.0""?>" & _
        "<fpquery version=""1.0"">" & _
        "<find tag=""b"">" & _
        "<rule type=""insideTag"" tag=""td"" />" & _
        "</find>" & _
        "<replace type=""changeTag"" tag=""i"" />" & _
        "</fpquery>"

    Set objRange = ActiveDocument.body.createTextRange
    Set objLimits = ActiveDocument.body.createTextRange
    Set objSearch = Application.CreateSearchInfo

    objSearch.Action = fpSearchFindTag
    objSearch.QueryContents = strQuery

    Do
        blnFoundMatch = Application.ActiveDocument.Find(objSearch, objLimits, objRange)
    Loop While blnFoundMatch = True
End Sub

Finding and Replacing Text Example 2

Function FindInFrontPage(ByRef objTargetPage As PageWindow, _
        ByVal strFind As String, ByVal blnMatchCase As Boolean, _
        ByVal blnFindWholeWord As Boolean, ByVal strText As String, _
        ByVal blnInsert As Boolean) As Boolean

    Dim objBody As IHTMLBodyElement
    Dim objTextRange As IHTMLTxtRange
    Dim blnFound As Boolean
    Dim lngFlags As Long

    Set objBody = objTargetPage.Document.body
    Set objTextRange = objBody.createTextRange

    FindInFrontPage = False

    If blnMatchCase = True Then lngFlags = lngFlags + 4
    If blnFindWholeWord = True Then lngFlags = lngFlags + 2

    objTextRange.collapse True

    Do
        blnFound = objTextRange.FindText(String:=strFind, _
            flags:=lngFlags)

        If blnFound Then
            If blnInsert = True Then
                objTextRange.collapse False
            End If
            objTextRange.Text = strText
            FindInFrontPage = True
            Exit Function
        End If
    Loop While blnFound = True

    Set objBody = Nothing
    Set objTextRange = Nothing

End Function


'Use the following subroutine to call the preceding function.
Sub CallFindInFrontPage()
    Dim blnFound As String
    Dim objPageWindow As PageWindow

    Set objPageWindow = Application.LocatePage( _
        DocumentURL:="example.htm", ViewMode:=fpPageViewNormal)

    blnFound = FindInFrontPage(objTargetPage:=objPageWindow, _
        strFind:="text to find", blnMatchCase:=True, _
        blnFindWholeWord:=True, strText:="text to add or replace", _
        blnInsert:=False)

    Select Case blnFound
        Case True
            MsgBox "Search text found and new text added successfully."
        Case False
            MsgBox "Unable to locate search text."
    End Select

End Sub

Inserting an Interactive Button

In FrontPage 2003, you can programmatically add interactive buttons to Web pages using the InsertInteractiveButton method of the FPHTMLDocument object. The following example adds the "Glow Capsule 1" button. When you add an interactive button to a Web page, FrontPage inserts the necessary scripts. When you remove an interactive button from a Web page, FrontPage removes the scripts.

The objects used in this example are as follows:

Inserting an Interactive Button Example

Sub InsertNewButton()
    Dim objSelection As IHTMLTxtRange

    Set objSelection = ActiveDocument.Selection.createRange

    ActiveDocument.InsertInteractiveButton objSelection, "fp-btn:Glow Capsule 1", _
        "Home", 200, 50, "http://www.microsoft.com", "_blank"
End Sub

Etc

Klemid's tools Fav2Web


Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Disclaimer:

Last modified: August 10, 2009