Softpanorama

May the source be with you, but remember the KISS principle ;-)
Contents Bulletin Scripting in shell and Perl Network troubleshooting History Humor

Frontpage Search and Replace

News

Microsoft FrontPage

Books

Recommended Links Stored Queries

Frontpage Regular Expressions

SSI

Code Snippets
FrontPage Macro Programming Document Object Model Keyboard shortcuts   History FrontPage Tips Humor Etc

Find and Replace has been enhanced in Microsoft FrontPage 2003, and now includes regular expressions. With stored queries (see Extending Find and Replace for Microsoft Office FrontPage 2003) it became a very powerful tool.

On Windows 7 queues are stored as XML files in the folder C:\Users\YourUserID\Appdata\Roaming\Microsoft\FrontPage\Queries. All stored search  and replace files of the have extension fpq

You can search one document or a group of documents or all the files in your website without opening each individual page to quickly find and replace content or even HTML.

To search multiple files you need to select only those that you want to analyze.

Attention: You can tab between Find and Replace.

Steps:

  1. On the Edit menu, select Find or Replace.
  2. In Find where:, select where to search by clicking Current page, Selected page(s) or All Pages.
  3. To find and replace content, click the Replace tab, enter your text in Find what:, and Replace with: and click Replace All or Replace.

Tips:  

You can encode search and replace operations in macros

Programming Find and Replace Operations

Using the above objects, methods, and properties, you can write very simple code that performs a textual find and replace. For example the following code takes the find and replace operation introduced at the beginning of this article and uses code to find all occurrences of "frist" and replace them with "first".

 

Copy
Sub SimpleFindAndReplace()

    Dim objSearch As SearchInfo

    Set objSearch = Application.CreateSearchInfo

    objSearch.Action = fpSearchReplaceAllText
    objSearch.Find = "frist"
    objSearch.ReplaceWith = "first"

    ActiveDocument.Find objSearch

End Sub

Note that the above code uses the CreateSearchInfo method to create an empty SearchInfo object. Then by using this empty object, the code specifies the action (to replace all text), the text ("frist"), and the replacement text ("first"). It then uses the Find method for the FPHTMLDocument object to execute a search by using the SearchInfo object.

Alternatively, you could use the QueryContents property of the CreateSearchInfo method along with the XML query string that you created earlier to create a comparable find and replace solution. For example, the following example does exactly the same thing as the previous example.

 

Copy
Sub QueryStringFindAndReplaceAll()

    Dim objSearch As SearchInfo

    Set objSearch = Application.CreateSearchInfo

    objSearch.QueryContents = "<?xml version=""1.0"" " & _
        "encoding=""utf-8"" ?>" & _
        "<fpquery version=""1.0"">" & _
        "<queryparams />" & _
        "<find text=""frist"" />" & _
        "<replace text=""first"" />" & _
        "</fpquery>"
    objSearch.Action = fpSearchReplaceAllText

    ActiveDocument.Find objSearch

End Sub

Note that the second example required several more lines. In this case, you set the QueryContents property to the query string that you created earlier in this article. You could also write this same code as show in the following example.

 

Copy
Sub QueryStringFindAndReplace()

    Dim objSearch As SearchInfo
    Dim objDocument As IHTMLTxtRange
    Dim objFound As IHTMLTxtRange
    Dim blnFound As Boolean

    Set objDocument = ActiveDocument.body.createTextRange
    Set objFound = ActiveDocument.body.createTextRange
    Set objSearch = Application.CreateSearchInfo

    objSearch.QueryContents = "<?xml version=""1.0"" " & _
        "encoding=""utf-8"" ?>" & _
        "<fpquery version=""1.0"">" & _
        "<queryparams />" & _
        "<find text=""frist"" />" & _
        "<replace text=""first"" />" & _
        "</fpquery>"
     objSearch.Action = fpSearchReplaceText

     Do
        blnFound = ActiveDocument.Find(objSearch, objDocument, objFound)
     Loop While blnFound = True

End Sub

The preceding example also sets the QueryContents property to the same query string. However, in this case, the code also uses the IHTMLTxtRange object. When you set the Action property to fpSearchReplaceText, you can use the Find method's two optional parameters to step through each change occurrence-by-occurrence. These two parameters require IHTMLTxtRange objects, so the code declares two different IHTMLTxtRange objects, which are then used in the Find method. The syntax for the Find method is as follows:

 

Copy
Find(info, limits, startRange)

The info parameter of the Find method specifies the SearchInfo object that contains the search text, rules, and options. Note that the second example above uses the QueryContents property to define a find and replace query, while the first example uses the Action, Find, and ReplaceWith properties of the SearchInfo object. This allows the SearchInfo object to identify the test to find and to specify the text with which to replace it.

The limits parameter specifies the IHTMLTxtRange object that represents the portion of the page against which to perform a find and replace. To search the entire document, you can use the createTextRange method of the FPHTMLBody object, as shown in the example above. This sets the limits of the range to search to the entire body of a page. However, you could also perform a find and replace against a selection by using the createRange method of the IHTMLSelectionObject object. This sets the limits for the range to search to only the text that is selected in the FrontPage window. The code to do this would look like the following example.

 

Copy
Set objDocument = ActiveDocument.Selection.createRange

The startRange parameter provides a reference to the found text. When the return value for the Find method is True, you can use the startRange parameter to select the found text. This is especially important if you want to step through a find and replace operation, stopping at each found word. In this case, you would set the Action property of the SearchInfo object equal to fpSearchReplaceText because the fpSearchReplaceText constant enables you to perform a find and replace that stops at each occurrence of found text.

Therefore, in the preceding example, if you wanted to select each occurrence as it is found, you could use the Select method of the IHTMLTxtRange object to select the returned text within the Do loop, as shown in the following sample.

 

Copy
Do
    blnFound = ActiveDocument.Find(objSearch, objDocument, objFound)
    objFound.Select
Loop While blnFound = True

Note The SearchInfo object allows you to perform textual find and replace only. You cannot perform replace operations that modify HTML. To do this, you can use the DocumentHTML property to perform a global search and replace of all occurrences of a string. The DocumentHTML property returns a string that represents both the HTML and the text for a Web page.

Programming with Regular Expressions

Using a query, you can easily perform find and replace operations that use regular expressions. To demonstrate this, the following example uses the SearchInfo object to execute a find based on a query string that uses a regular expression. The regular expression it specified is " t:a*n ". This regular expression will locate all words that start with a "t" and end with an "n". For example, it will locate tan, ten, ton, tin, and teen as well as Tennessean. The asterisk indicates that any number of letters can occur between the "t" and the "n". For more information see, Regular Expressions.

 

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

    strQuery = "<fpquery version=""1.0"">" & _
        "<queryparams regexp=""true"" />" & _
        "<find text=""t:a*n"" />" & _
        "</fpquery>"

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

    objSearch.Action = fpSearchFindText
    objSearch.QueryContents = strQuery

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

Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

macros: find is unable to replace text in source: queryparams inhtml=true does not replace in html

Feb 08, 2007

macros: find is unable to replace text in source: queryparams inhtml=true does not replace in html

Archived from groups: microsoft>public>frontpage>programming (more info?)

I'm doing VBA (macros) in the latest FrontPage 2003 with all updates. However, is there still buggy stuff?

Using a SearchInfo, find replaces all the displayed text fine but seems to ignore in-html (can't replace text in the source code).

I can do it fine manually via the Find & Replace window, but (as a workaround) I don't know how to fill out the windows' fields via a VBA
macro.

And it looks like possibly others have also had this bug (macros can't
find & replace text in source):
http://groups.google.com/group/microsoft.public.frontpage.client/browse_thread/thread/37651078df52d65f/0914f35bb6b75ed2?lnk=st&q=inhtml+queryparams&rnum=1#0914f35bb6b75ed2
(Automation of Find & Replace using VB) says "strQuery works but the
strRating query does not - at least not inside the code, it works as a standalone normal FrontPage query."

Here's my code, almost straight from Microsoft's examples:

Sub QueryStringFindAndReplaceAll()
' 20070208+08+035539 by MBParker
' based on the subprocedure with same name in http://
msdn2.microsoft.com/en-us/library/aa218656(office.11).aspx
' but with the addition of inhtml=true ("Searches for the find string in the HTML source code.")
'-- BUT the inhtml seems to have no effect; it only replaces in the displayed HTML output
'Even the advanced varient (commented out here) does nothing more, either.

' Dim objDocument As IHTMLTxtRange
' Set objDocument = ActiveDocument.body.createTextRange
' Dim objFound As IHTMLTxtRange
' Set objFound = ActiveDocument.body.createTextRange
Dim objSearch As SearchInfo
Set objSearch = Application.CreateSearchInfo
objSearch.QueryContents = "<?xml version=""1.0"" " & _
"encoding=""utf-8"" ?>" & _
"<fpquery version=""1.0"">" & _
"<queryparams inhtml=""true"" />" & _
"<find text=""20070208053013"" />" & _
"<replace text=""" & GUID() & """ />" & _
"</fpquery>"

'Simple version:
objSearch.Action = fpSearchReplaceAllText
ActiveDocument.Find objSearch

'Advanced version:
' objSearch.Action = fpSearchReplaceText
' Dim blnFound As Boolean
' Do
' blnFound = ActiveDocument.Find(objSearch, objDocument,
objFound)
' Loop While blnFound = True
End Sub

Any ideas? Thanks!

Mike B. Parker
► Now Designing www.CommuniDB.com ―“Your Community Database”™ (Web
2.0) -- and we could sure use some automated GUIDs!

[Mar 23, 2011] Extending Find and Replace for Microsoft Office FrontPage 2003

Using the above objects, methods, and properties, you can write very simple code that performs a textual find and replace. For example the following code takes the find and replace operation introduced at the beginning of this article and uses code to find all occurrences of "frist" and replace them with "first".

Sub SimpleFindAndReplace()
   Dim objSearch As SearchInfo
   Set objSearch = Application.CreateSearchInfo

   objSearch.Action = fpSearchReplaceAllText
   objSearch.Find = "frist"
   objSearch.ReplaceWith = "first"

   ActiveDocument.Find objSearch

End Sub

Note that the above code uses the CreateSearchInfo method to create an empty SearchInfo object. Then by using this empty object, the code specifies the action (to replace all text), the text ("frist"), and the replacement text ("first"). It then uses the Find method for the FPHTMLDocument object to execute a search by using the SearchInfo object.

Alternatively, you could use the QueryContents property of the CreateSearchInfo method along with the XML query string that you created earlier to create a comparable find and replace solution. For example, the following example does exactly the same thing as the previous example.

Copy
Sub QueryStringFindAndReplaceAll()

    Dim objSearch As SearchInfo

    Set objSearch = Application.CreateSearchInfo

    objSearch.QueryContents = "<?xml version=""1.0"" " & _
        "encoding=""utf-8"" ?>" & _
        "<fpquery version=""1.0"">" & _
        "<queryparams />" & _
        "<find text=""frist"" />" & _
        "<replace text=""first"" />" & _
        "</fpquery>"
    objSearch.Action = fpSearchReplaceAllText

    ActiveDocument.Find objSearch

End Sub

Note that the second example required several more lines. In this case, you set the QueryContents property to the query string that you created earlier in this article. You could also write this same code as show in the following example.

Copy
Sub QueryStringFindAndReplace()

    Dim objSearch As SearchInfo
    Dim objDocument As IHTMLTxtRange
    Dim objFound As IHTMLTxtRange
    Dim blnFound As Boolean

    Set objDocument = ActiveDocument.body.createTextRange
    Set objFound = ActiveDocument.body.createTextRange
    Set objSearch = Application.CreateSearchInfo

    objSearch.QueryContents = "<?xml version=""1.0"" " & _
        "encoding=""utf-8"" ?>" & _
        "<fpquery version=""1.0"">" & _
        "<queryparams />" & _
        "<find text=""frist"" />" & _
        "<replace text=""first"" />" & _
        "</fpquery>"
     objSearch.Action = fpSearchReplaceText

     Do
        blnFound = ActiveDocument.Find(objSearch, objDocument, objFound)
     Loop While blnFound = True

End Sub

The preceding example also sets the QueryContents property to the same query string. However, in this case, the code also uses the IHTMLTxtRange object. When you set the Action property to fpSearchReplaceText, you can use the Find method's two optional parameters to step through each change occurrence-by-occurrence. These two parameters require IHTMLTxtRange objects, so the code declares two different IHTMLTxtRange objects, which are then used in the Find method. The syntax for the Find method is as follows:

Copy
Find(info, limits, startRange)

The info parameter of the Find method specifies the SearchInfo object that contains the search text, rules, and options. Note that the second example above uses the QueryContents property to define a find and replace query, while the first example uses the Action, Find, and ReplaceWith properties of the SearchInfo object. This allows the SearchInfo object to identify the test to find and to specify the text with which to replace it.

The limits parameter specifies the IHTMLTxtRange object that represents the portion of the page against which to perform a find and replace. To search the entire document, you can use the createTextRange method of the FPHTMLBody object, as shown in the example above. This sets the limits of the range to search to the entire body of a page. However, you could also perform a find and replace against a selection by using the createRange method of the IHTMLSelectionObject object. This sets the limits for the range to search to only the text that is selected in the FrontPage window. The code to do this would look like the following example.

Copy
Set objDocument = ActiveDocument.Selection.createRange

The startRange parameter provides a reference to the found text. When the return value for the Find method is True, you can use the startRange parameter to select the found text. This is especially important if you want to step through a find and replace operation, stopping at each found word. In this case, you would set the Action property of the SearchInfo object equal to fpSearchReplaceText because the fpSearchReplaceText constant enables you to perform a find and replace that stops at each occurrence of found text.

Therefore, in the preceding example, if you wanted to select each occurrence as it is found, you could use the Select method of the IHTMLTxtRange object to select the returned text within the Do loop, as shown in the following sample.

Copy
Do
    blnFound = ActiveDocument.Find(objSearch, objDocument, objFound)
    objFound.Select
Loop While blnFound = True

Note The SearchInfo object allows you to perform textual find and replace only. You cannot perform replace operations that modify HTML. To do this, you can use the DocumentHTML property to perform a global search and replace of all occurrences of a string. The DocumentHTML property returns a string that represents both the HTML and the text for a Web page.

Programming with Regular Expressions

Using a query, you can easily perform find and replace operations that use regular expressions. To demonstrate this, the following example uses the SearchInfo object to execute a find based on a query string that uses a regular expression. The regular expression it specified is " t:a*n ". This regular expression will locate all words that start with a "t" and end with an "n". For example, it will locate tan, ten, ton, tin, and teen as well as Tennessean. The asterisk indicates that any number of letters can occur between the "t" and the "n". For more information see, Regular Expressions.

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

    strQuery = "<fpquery version=""1.0"">" & _
        "<queryparams regexp=""true"" />" & _
        "<find text=""t:a*n"" />" & _
        "</fpquery>"

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

    objSearch.Action = fpSearchFindText
    objSearch.QueryContents = strQuery

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

How To Perform a Global Find and Replace

With Microsoft FrontPage 2000 new find and replace, you can edit all of your pages at the same time. Suppose you have multiple pages that contain a now outdated email address. You could find this item and replace it with the new address in all your pages without opening each page.

Feature to Use

Specific Steps to Take

To perform a global Find and Replace:

  1. Click Edit, then Replace.
  2. Enter the target word or phrase in the Find what: field. Enter the new word or phrase in the Replace with: field.
  3. Under Search Options, click All pages.

Recommended Links

Softpanorama hot topic of the month

Softpanorama Recommended



Etc

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit exclusivly for research and educational purposes.   If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner. 

ABUSE: IPs or network segments from which we detect a stream of probes might be blocked for no less then 90 days. Multiple types of probes increase this period.  

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haters Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least


Copyright 1996-2016 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. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License.

The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting development of this site and speed up access. In case softpanorama.org is down you can use the at softpanorama.info

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: November, 07, 2016