Replace ff (and the following pages) with proteced spaces between'Page', the number and ff

A

andreas

Dear Experts:

I would like to replace programmatically via VBA all of the following
expressions with the same expressions but with protected spaces
between the word 'Page', the number and ff

Examples:

Page 2 ff or

Page 375 ff

Your professional help is much appreciated. Thank you very much in
advance.

Regards, Andreas
 
P

Pablo Cardellino

Hi, Andreas,

Im not an expert, but try this:

Sub ReplaceSpacesWithinPageNumber()
Dim d As Range

Set d = ActiveDocument.Range

d.Find.ClearFormatting
d.Find.Replacement.ClearFormatting
With d.Find
.Text = "<page ([0-9]{1;}) ff>"
.Replacement.Text = "Page^s\1^sff"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
d.Find.Execute Replace:=wdReplaceAll

End Sub

Regards,

Pablo
 
A

andreas

Hi, Andreas,

Im not an expert, but try this:

Sub ReplaceSpacesWithinPageNumber()
    Dim d As Range

    Set d = ActiveDocument.Range

    d.Find.ClearFormatting
    d.Find.Replacement.ClearFormatting
    With d.Find
        .Text = "<page ([0-9]{1;}) ff>"
        .Replacement.Text = "Page^s\1^sff"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    d.Find.Execute Replace:=wdReplaceAll

End Sub

Regards,

Pablo

"andreas" <[email protected]> escreveu na mensagem

Dear Experts:
I would like to replace programmatically via VBA all of the following
expressions with the same expressions but with protected spaces
between the word 'Page', the number and ff

Page 2 ff   or
Page 375 ff
Your professional help is much appreciated. Thank you very much in
advance.
Regards, Andreas- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hey Pablo.

exactly what I wanted. Very good job. Thank you very much for your
professional help.

Regards, Andreas
 
H

Helmut Weber

Hi Pablo,

I don't want to be obtrusive,
but as I think, any hint would be appreciated,
when you create a new range,
all parameters are set to default values,
so the following would be sufficient:

Sub ReplaceSpacesWithinPageNumber()
Dim d As Range
Set d = ActiveDocument.Range
With d.Find
.Text = "<page ([0-9]{1;}) ff>"
.Replacement.Text = "Page^s\1^sff"
.Execute Replace:=wdReplaceAll
End With
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
P

Pablo Cardellino

Hi, helmut,
when you create a new range,
all parameters are set to default values,

I didn't know that, I thought that the present Selection.Find parameters
were used. Your suggestion is very useful, thanks.

Regards,

Pablo

--
Pablo Cardellino
Florianópolis, SC
Brazil


Helmut Weber said:
Hi Pablo,

I don't want to be obtrusive,
but as I think, any hint would be appreciated,
when you create a new range,
all parameters are set to default values,
so the following would be sufficient:

Sub ReplaceSpacesWithinPageNumber()
Dim d As Range
Set d = ActiveDocument.Range
With d.Find
.Text = "<page ([0-9]{1;}) ff>"
.Replacement.Text = "Page^s\1^sff"
.Execute Replace:=wdReplaceAll
End With
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
P

Pablo Cardellino

Helmut,

but the MatchWildcards option isn't true by default, is it? If not, it is
needed to. Anyway, your hint is very useful.

Regards,

Pablo
 
H

Helmut Weber

Hi Pablo,
but the MatchWildcards option isn't true by default, is it?

it is not. My fault! <gr>
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
J

Jay Freedman

Helmut's advice is good, and it has an additional implication: The settings of
Selection.Find are "sticky" -- that is, anything the user (or a macro) set in
the most recent previous search remains set for the current search. In contrast,
when you initialize a new Range object, its .Find settings are all the defaults.

This is yet another reason to use a Range instead of the Selection for searches,
besides the fact that it doesn't move the insertion point. It helps to avoid
searches that do unexpected things because of left-over settings.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

Hi, helmut,
when you create a new range,
all parameters are set to default values,

I didn't know that, I thought that the present Selection.Find parameters
were used. Your suggestion is very useful, thanks.

Regards,

Pablo

--
Pablo Cardellino
Florianópolis, SC
Brazil


Helmut Weber said:
Hi Pablo,

I don't want to be obtrusive,
but as I think, any hint would be appreciated,
when you create a new range,
all parameters are set to default values,
so the following would be sufficient:

Sub ReplaceSpacesWithinPageNumber()
Dim d As Range
Set d = ActiveDocument.Range
With d.Find
.Text = "<page ([0-9]{1;}) ff>"
.Replacement.Text = "Page^s\1^sff"
.Execute Replace:=wdReplaceAll
End With
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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