PC Review


Reply
Thread Tools Rate Thread

Automation of Find & Replace using VB

 
 
=?Utf-8?B?RGFp?=
Guest
Posts: n/a
 
      16th Jun 2005
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


 
Reply With Quote
 
 
 
 
Thomas A. Rowe
Guest
Posts: n/a
 
      16th Jun 2005
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)
http://www.ycoln-resources.com
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.
==============================================

"Dai" <(E-Mail Removed)> wrote in message
news:0EF1690B-6AF5-4F01-85D1-(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
=?Utf-8?B?RGFp?=
Guest
Posts: n/a
 
      17th Jun 2005
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

"Thomas A. Rowe" wrote:

> 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)
> http://www.ycoln-resources.com
> 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.
> ==============================================
>
> "Dai" <(E-Mail Removed)> wrote in message
> news:0EF1690B-6AF5-4F01-85D1-(E-Mail Removed)...
> > 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
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace images thru automation =?Utf-8?B?QVdJY3VycmVudA==?= Microsoft Word Document Management 1 11th Oct 2005 02:39 PM
word automation find and replace James Vitale Microsoft ASP .NET 1 16th Sep 2005 08:19 AM
Word Automation - Find/Replace =?Utf-8?B?Sk1C?= Microsoft Excel Misc 2 21st May 2005 10:34 PM
Excel Automation - Find/Replace scorpion53061 Microsoft VB .NET 2 30th Jan 2004 10:54 PM
Excel Automation Find/Replace Excel 2000 and 2003 scorpion53061 Microsoft Excel Programming 0 30th Jan 2004 10:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:44 PM.