Replace macro problem

  • Thread starter Francis Hookham
  • Start date
F

Francis Hookham

As an administrator I have to make changes to a website page. For reasons I
do not understand, on saving, the links in the page default to the Home
page, rather than to the intended links within the page.



The solution is to remove "?ide=###" from the HTML, where ### is the three
digit page ID.



I can do this by copying HTML into Word and simply finding "?ide=" in order
to see what is the three digit number. Then, using that information, replace
it with "".



It would be great to automate this as much as possible so I recorded the
macro below. The problem is that it is specific, having recorded that
particular page, "?ide=360"



How can the macro pick up any page number? I suppose what I am asking is,
after the Find, how can the next three characters be selected and the whole
"?ide=###" be selected irrespective of what the ### is?



(A deeper question might be to wonder about four characters since the fourth
is a hash suggesting the website can cope with 9,999 pages rather than 999
pages. So a macro which senses the whether the fourth character as a hash or
not and replacing accordingly might be necessary in a year or two! Any
thoughts on that at this stage?)



Many thanks



Francis Hookham



Sub ideRemoval()

Selection.Find.ClearFormatting

With Selection.Find

.Text = "?ide="

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend

Selection.Copy

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find

.Text = "?ide=360"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindAsk

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

Selection.WholeStory

Selection.Copy

End Sub
 
G

Graham Mayor

Use a wildcard replace of
\?ide=[0-9]{1,}
with
nothing
which will replace any number of digits after the =. You can limit to 4 if
you want {1,4}

Sub ideRemoval()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\?ide=[0-9]{1,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute replace:=wdReplaceAll
End With
End Sub

See http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

Francis Hookham

Many thanks Graham - just what I wanted.

Francis


Graham Mayor said:
Use a wildcard replace of
\?ide=[0-9]{1,}
with
nothing
which will replace any number of digits after the =. You can limit to 4 if
you want {1,4}

Sub ideRemoval()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\?ide=[0-9]{1,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute replace:=wdReplaceAll
End With
End Sub

See http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Francis said:
As an administrator I have to make changes to a website page. For
reasons I do not understand, on saving, the links in the page default
to the Home page, rather than to the intended links within the page.



The solution is to remove "?ide=###" from the HTML, where ### is the
three digit page ID.



I can do this by copying HTML into Word and simply finding "?ide=" in
order to see what is the three digit number. Then, using that
information, replace it with "".



It would be great to automate this as much as possible so I recorded
the macro below. The problem is that it is specific, having recorded
that particular page, "?ide=360"



How can the macro pick up any page number? I suppose what I am asking
is, after the Find, how can the next three characters be selected and
the whole "?ide=###" be selected irrespective of what the ### is?



(A deeper question might be to wonder about four characters since the
fourth is a hash suggesting the website can cope with 9,999 pages
rather than 999 pages. So a macro which senses the whether the fourth
character as a hash or not and replacing accordingly might be
necessary in a year or two! Any thoughts on that at this stage?)



Many thanks



Francis Hookham



Sub ideRemoval()

Selection.Find.ClearFormatting

With Selection.Find

.Text = "?ide="

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend

Selection.Copy

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find

.Text = "?ide=360"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindAsk

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

Selection.WholeStory

Selection.Copy

End Sub
 

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