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
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