Automation of Find & Replace using VB

D

Dai

Hi,

I'm trying to automate a find and replace which strips out the Frontpage
extensions to provide a copy of a web-site for a customer. My program works
when it comes to removing forms but not when I try to remove certain pieces
of text outside those forms. I've included the complete piece of code below.
The strQuery works but the strRating query does not - at least not inside
the code, it works as a standalone normal Frontpage query. Can anyone see
what is wrong with it? Thanks

Here's the complete code, feel free to copy and use it yourselves:

Public objFile As webFile

Public objApp As FrontPage.Application

Public objPageWindow As PageWindowEx

Public objHead As IHTMLElement

Public objSearch As SearchInfo

Public objRange As IHTMLTxtRange
Public objLimits As IHTMLTxtRange

Public strQuery As String
Public strRating As String

Public intFilesCount As Integer
Public intFC As Integer

Public blnFoundMatch As Boolean

Sub RemovingTheFormsAndRatings()

Set objApp = FrontPage.Application
intFC = 0

'
' Set up the Form code search string
'
strQuery = "<?xml version=""1.0""?>" & _
"<fpquery version=""1.0"">" & _
"<queryparams regexp=""true"" inhtml=""true"" />" & _
"<find tag=""form"">" & _
"</find>" & _
"<replace type=""removeTagAndContents"" />" & _
"</fpquery>"

'
' Set up the Rating code search string
'
strRating = "<?xml version=""1.0""?>" & _
"<fpquery version=""1.0"">" & _
"<queryparams regexp=""true"" inhtml=""true"" />" & _
"<find tag=""a"">" & _
"<rule type=""attribute"" attribute=""name"" compare=""=""
value=""rate"" />" & _
"</find>" & _
"<replace type=""removeTagAndContents"" />" & _
"</fpquery>"

'
'Create a reference to the webFiles collection.
'

intFilesCount = objApp.ActiveWeb.AllFiles.Count

For Each objFile In objApp.ActiveWeb.AllFiles
If objFile.Extension = "htm" Or objFile.Extension = "html" Then
objFile.Open
Set objPageWindow = ActivePageWindow
Set objPage = objPageWindow.Document
'
' Replace the code for the Rating if it exists
'
Set objSearch = Application.CreateSearchInfo

objSearch.Action = fpSearchFindTag
objSearch.QueryContents = strRating

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

'
' Find and replace the code for the form if it exists
'
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


'Now save and close the page window.

objPageWindow.SaveAs objPageWindow.Document.Url
objPageWindow.Close False
End If
If intFC < intFilesCount Then
intFC = intFC + 1
Else
Exit For
End If
Next objFile

End Sub
 
T

Thomas A. Rowe

If using FP2003, publish the site to another location and enable all the Optimize HTML options which
will remove all Webbot related code, etc.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WebMaster Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
D

Dai

Thanks Thomas

That will help remove the forms unfortunatley the pages aren't that well
designed and some text relating to the forms is outside of the form and thus
needed to be removed manually. Fortunately after posting this question I was
able solve the problem.

The first query was missing some vital prameters :

Set objRange = ActiveDocument.body.createTextRange
Set objLimits = ActiveDocument.body.createTextRange

which should be set-up as part of each & every query and placed as per the
form query, before:

Set objSearch = Application.CreateSearchInfo

In a previous incarnation of this problem the form query had come first, but
the result for the rating query had still be nill point, and for some reason
loss on me I'd not assortcated the two.

I'd been too close to the fire.

Thanks for your help

Dai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top