Remove extra space in initials ...

S

StargateFan

Last one today, I PROMISE <g>.

I've had the situation come up in my clean-up macros that after
putting correct spaces after each line, that the script interprets
initials in the same way.

Trying to use my newfound knowledge, I tried this below:

-----------------------------------------------------------------------
Sub RemoveSpaceInInitials()

With ActiveDocument.Range.Find

.Execute FindText:=" ^?. ", ReplaceWith:=" ^?. ",
Replace:=wdReplaceAll

End With

End Sub
 
D

Doug Robbins - Word MVP

Use a wildcard replace with

([A-Z]{1}.)[two spaces]([A-Z]{1})

for find what and

\1[one space]\2

for the replace with.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

StargateFan

Use a wildcard replace with

([A-Z]{1}.)[two spaces]([A-Z]{1})

for find what and

\1[one space]\2

for the replace with.

I bet I've done something wrong!

I tried the above in this:

Sub INITIALS_fixSpacesAfter()
With ActiveDocument.Range.Find
.Execute FindText:="([A-Z]{1}.)[two spaces]([A-Z]{1})",
ReplaceWith:="\1[one space]\2", Replace:=wdReplaceAll
End With
End Sub

Nothing seems to happen and the changes aren't made. what am I doing
 
D

Doug Robbins - Word MVP

You would have to turn on wildcards and in place of [two spaces] and [one
space], you were intended to insert the appropriate number of spaces using
the space bar. After all, that was the whole point of the exercise.

With ActiveDocument.Range.Find
.Execute findText:="([A-Z]{1}.) ([A-Z]{1})", MatchWildcards:=True,
_
ReplaceWith:="\1 \2", Replace:=wdReplaceAll
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

StargateFan said:
Use a wildcard replace with

([A-Z]{1}.)[two spaces]([A-Z]{1})

for find what and

\1[one space]\2

for the replace with.

I bet I've done something wrong!

I tried the above in this:

Sub INITIALS_fixSpacesAfter()
With ActiveDocument.Range.Find
.Execute FindText:="([A-Z]{1}.)[two spaces]([A-Z]{1})",
ReplaceWith:="\1[one space]\2", Replace:=wdReplaceAll
End With
End Sub

Nothing seems to happen and the changes aren't made. what am I doing
wrong said:
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

StargateFan

You would have to turn on wildcards and in place of [two spaces] and [one
space], you were intended to insert the appropriate number of spaces using
the space bar. After all, that was the whole point of the exercise.

Hi.

Responding to your (faintly patronizing ... faintly sarcastic ... <g>)
message, thanks for this. I'm a dunce when it comes to vb, this
proves it yet again <g>.

This made me laugh this morning, I'm sorry. One has to laugh at my
mistake. Didn't even realize I was doing it, of course.
With ActiveDocument.Range.Find
.Execute findText:="([A-Z]{1}.) ([A-Z]{1})", MatchWildcards:=True,
_
ReplaceWith:="\1 \2", Replace:=wdReplaceAll
End With

It is probably my fault in not explaining properly, but what is
happening is that I'm still left with 2 spaces after the second
initial. For over half hour I've tried and tried to fix this but I
don't know how.

The macro seems to work just great for the first part. It replaced
the 2 spaces with none between the repeating 2 initials throughout the
document (I modified it from "\1 \2" above to "\1\2"). I never
considered that the 2 initials might be a different issue from one.
My mistake. Well, at any rate, this is what happens:

A.[2 spaces]B.[2 spaces]Someone (see, I learn ... <g>)
A.B.[2 spaces]Someone

Did searches on vbe and archives for wildcards and syntax or
parameters, or whatever we're talking about here would be called, but
nothing came up.

Ideally, of course, one would need to keep the double spaces between
sentences but have only one space after all initials and no spaces
between the initials themselves, no matter how many there would be.
So, pls bear with me, hoping someone here could help fix this final
step.

Seriously, not all of us who post in these ngs have any real expertise
to speak of so what is obvious to you all, is not to us. Appreciate
the help very much said:
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

StargateFan said:
Use a wildcard replace with

([A-Z]{1}.)[two spaces]([A-Z]{1})

for find what and

\1[one space]\2

for the replace with.

I bet I've done something wrong!

I tried the above in this:

Sub INITIALS_fixSpacesAfter()
With ActiveDocument.Range.Find
.Execute FindText:="([A-Z]{1}.)[two spaces]([A-Z]{1})",
ReplaceWith:="\1[one space]\2", Replace:=wdReplaceAll
End With
End Sub

Nothing seems to happen and the changes aren't made. what am I doing
wrong said:
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Last one today, I PROMISE <g>.

I've had the situation come up in my clean-up macros that after
putting correct spaces after each line, that the script interprets
initials in the same way.

Trying to use my newfound knowledge, I tried this below:

-----------------------------------------------------------------------
Sub RemoveSpaceInInitials()

With ActiveDocument.Range.Find

.Execute FindText:=" ^?. ", ReplaceWith:=" ^?. ",
Replace:=wdReplaceAll

End With

End Sub
-----------------------------------------------------------------------

But both the macro and when done manually in the dialogue box don't
recognize the ^? in the replace box. What is the best way to do this,
then, pls? Thankx much.
 
D

Doug Robbins - Word MVP

If you want to remove the two spaces between the initial and the name, try
"([A-Z]{1}.) ([A-z']{1,})"

as the text to be found.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

StargateFan said:
You would have to turn on wildcards and in place of [two spaces] and [one
space], you were intended to insert the appropriate number of spaces using
the space bar. After all, that was the whole point of the exercise.

Hi.

Responding to your (faintly patronizing ... faintly sarcastic ... <g>)
message, thanks for this. I'm a dunce when it comes to vb, this
proves it yet again <g>.

This made me laugh this morning, I'm sorry. One has to laugh at my
mistake. Didn't even realize I was doing it, of course.
With ActiveDocument.Range.Find
.Execute findText:="([A-Z]{1}.) ([A-Z]{1})",
MatchWildcards:=True,
_
ReplaceWith:="\1 \2", Replace:=wdReplaceAll
End With

It is probably my fault in not explaining properly, but what is
happening is that I'm still left with 2 spaces after the second
initial. For over half hour I've tried and tried to fix this but I
don't know how.

The macro seems to work just great for the first part. It replaced
the 2 spaces with none between the repeating 2 initials throughout the
document (I modified it from "\1 \2" above to "\1\2"). I never
considered that the 2 initials might be a different issue from one.
My mistake. Well, at any rate, this is what happens:

A.[2 spaces]B.[2 spaces]Someone (see, I learn ... <g>)
A.B.[2 spaces]Someone

Did searches on vbe and archives for wildcards and syntax or
parameters, or whatever we're talking about here would be called, but
nothing came up.

Ideally, of course, one would need to keep the double spaces between
sentences but have only one space after all initials and no spaces
between the initials themselves, no matter how many there would be.
So, pls bear with me, hoping someone here could help fix this final
step.

Seriously, not all of us who post in these ngs have any real expertise
to speak of so what is obvious to you all, is not to us. Appreciate
the help very much said:
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

StargateFan said:
On Sat, 24 Mar 2007 17:09:14 +0100, "Doug Robbins - Word MVP"

Use a wildcard replace with

([A-Z]{1}.)[two spaces]([A-Z]{1})

for find what and

\1[one space]\2

for the replace with.

I bet I've done something wrong!

I tried the above in this:

Sub INITIALS_fixSpacesAfter()
With ActiveDocument.Range.Find
.Execute FindText:="([A-Z]{1}.)[two spaces]([A-Z]{1})",
ReplaceWith:="\1[one space]\2", Replace:=wdReplaceAll
End With
End Sub

Nothing seems to happen and the changes aren't made. what am I doing
wrong, pls? <g>

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Last one today, I PROMISE <g>.

I've had the situation come up in my clean-up macros that after
putting correct spaces after each line, that the script interprets
initials in the same way.

Trying to use my newfound knowledge, I tried this below:

-----------------------------------------------------------------------
Sub RemoveSpaceInInitials()

With ActiveDocument.Range.Find

.Execute FindText:=" ^?. ", ReplaceWith:=" ^?. ",
Replace:=wdReplaceAll

End With

End Sub
-----------------------------------------------------------------------

But both the macro and when done manually in the dialogue box don't
recognize the ^? in the replace box. What is the best way to do this,
then, pls? Thankx much.
 
S

StargateFan

If you want to remove the two spaces between the initial and the name, try
"([A-Z]{1}.) ([A-z']{1,})"

That worked once I added the space back between the \1 and \2, who
knows why ... (?) <g>

I'll be looking for references to wildcards now. I haven't seen
enough examples to figure out beyond the obvious. I did find this
page via an archives message, thought I'd mention:
http://www.gmayor.com/replace_using_wildcards.htm
This helped a lot but I'll have to study it.

Thanks for your help. Much appreciated. I ran a test and it seemed
to fix _just_ the initials which was important.

My goal with this "clean-up" template with these macros is to have an
easy way to clean up text saved from the internet. It seems to be
doing a great job so far. It's sure going to save me future hours and
hours of work. Up until now, I'd had to restrict how much research to
do because of the problems with the resulting text and how long it
took to reformat despite any tricks I did know how to do. But now
will be able to proceed at a much faster pace thanks to all this.

Cheers. :eek:D
as the text to be found.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

StargateFan said:
You would have to turn on wildcards and in place of [two spaces] and [one
space], you were intended to insert the appropriate number of spaces using
the space bar. After all, that was the whole point of the exercise.

Hi.

Responding to your (faintly patronizing ... faintly sarcastic ... <g>)
message, thanks for this. I'm a dunce when it comes to vb, this
proves it yet again <g>.

This made me laugh this morning, I'm sorry. One has to laugh at my
mistake. Didn't even realize I was doing it, of course.
With ActiveDocument.Range.Find
.Execute findText:="([A-Z]{1}.) ([A-Z]{1})",
MatchWildcards:=True,
_
ReplaceWith:="\1 \2", Replace:=wdReplaceAll
End With

It is probably my fault in not explaining properly, but what is
happening is that I'm still left with 2 spaces after the second
initial. For over half hour I've tried and tried to fix this but I
don't know how.

The macro seems to work just great for the first part. It replaced
the 2 spaces with none between the repeating 2 initials throughout the
document (I modified it from "\1 \2" above to "\1\2"). I never
considered that the 2 initials might be a different issue from one.
My mistake. Well, at any rate, this is what happens:

A.[2 spaces]B.[2 spaces]Someone (see, I learn ... <g>)
A.B.[2 spaces]Someone

Did searches on vbe and archives for wildcards and syntax or
parameters, or whatever we're talking about here would be called, but
nothing came up.

Ideally, of course, one would need to keep the double spaces between
sentences but have only one space after all initials and no spaces
between the initials themselves, no matter how many there would be.
So, pls bear with me, hoping someone here could help fix this final
step.

Seriously, not all of us who post in these ngs have any real expertise
to speak of so what is obvious to you all, is not to us. Appreciate
the help very much said:
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

On Sat, 24 Mar 2007 17:09:14 +0100, "Doug Robbins - Word MVP"

Use a wildcard replace with

([A-Z]{1}.)[two spaces]([A-Z]{1})

for find what and

\1[one space]\2

for the replace with.

I bet I've done something wrong!

I tried the above in this:

Sub INITIALS_fixSpacesAfter()
With ActiveDocument.Range.Find
.Execute FindText:="([A-Z]{1}.)[two spaces]([A-Z]{1})",
ReplaceWith:="\1[one space]\2", Replace:=wdReplaceAll
End With
End Sub

Nothing seems to happen and the changes aren't made. what am I doing
wrong, pls? <g>

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Last one today, I PROMISE <g>.

I've had the situation come up in my clean-up macros that after
putting correct spaces after each line, that the script interprets
initials in the same way.

Trying to use my newfound knowledge, I tried this below:

-----------------------------------------------------------------------
Sub RemoveSpaceInInitials()

With ActiveDocument.Range.Find

.Execute FindText:=" ^?. ", ReplaceWith:=" ^?. ",
Replace:=wdReplaceAll

End With

End Sub
-----------------------------------------------------------------------

But both the macro and when done manually in the dialogue box don't
recognize the ^? in the replace box. What is the best way to do this,
then, pls? Thankx much.
 
S

StargateFan

If you want to remove the two spaces between the initial and the name, try
"([A-Z]{1}.) ([A-z']{1,})"

[snip]

I give up. This worked in a test file but when I added it in to the
main clean up macro, it didn't. When I took out the space between the
\1 and \2, just like in the original macro, it at least took out the
space between the two initials but left the two spaces after ...
<sigh>.

Well, go figure. I have errands to run so maybe when I come back I'll
tackle it again and maybe I'll stumble over what's up with this one.
 
G

Graham Mayor

It helps if you explain *exactly* what you are trying to achieve. Without
the total picture, suggestions are blind.

It seems you now want to remove the extra spaces between two initials and a
surname? The following string will do that
([A-Z].)[<space>]{2}
replace with
\1<space>
however, it makes no account for whatever else you might have in your
document. This will remove the extra space from any sentence that ends in a
capital letter and full stop/period - which will include initials.

Wouldn't it be better simply to remove all double spaces? They are
unnecessary in a word-processed document that uses proportional fonts.
([<space>]){1,}
replace with
\1

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


If you want to remove the two spaces between the initial and the
name, try "([A-Z]{1}.) ([A-z']{1,})"

[snip]

I give up. This worked in a test file but when I added it in to the
main clean up macro, it didn't. When I took out the space between the
\1 and \2, just like in the original macro, it at least took out the
space between the two initials but left the two spaces after ...
<sigh>.

Well, go figure. I have errands to run so maybe when I come back I'll
tackle it again and maybe I'll stumble over what's up with this one.
 
S

StargateFan

It helps if you explain *exactly* what you are trying to achieve. Without
the total picture, suggestions are blind.

Yes, thanks. However, omniscience is not something I can make claims
to ... <g>. If I'd known of the problems ahead of time, naturally I
would have mentioned them said:
It seems you now want to remove the extra spaces between two initials and a
surname? The following string will do that

The goals I started out with re this script are the same now as they
were then. Nothing has changed, and one of those goals is to correct
spaces between sentences.

That I ran into double initials was not something I anticipated. Good
thing to had this in my first, test doct., wouldn't you agree?
([A-Z].)[<space>]{2}
replace with
\1<space>
however, it makes no account for whatever else you might have in your
document. This will remove the extra space from any sentence that ends in a
capital letter and full stop/period - which will include initials.

Wouldn't it be better simply to remove all double spaces? They are
unnecessary in a word-processed document that uses proportional fonts.

Thank you. One of the whole purposes of the clean-up doct. is to
present a properly word-processed doct. With your code above, I'll
work with all that I now know and will achieve the double spacing
between sentences without having double initials affected. That the
odd initial and surname will have a double space is not a problem.
I'll catch it during the manual cleanup and fix it. Proofreading my
work is I have over 25 years experience with so I can do that in my
sleep <g>.

There are rarely initials to work with, double initials even less so,
but this doct. should cover practically everything.
([<space>]){1,}
replace with
\1

Thanks. Now that I have examples of all this weird coding, hopefully
I can now start to make sense of it for myself so that I can come up
with my own combinatios.

Funny how since 1987 I could write up macros in every WordPerfect
version that has ever come along. Yet with vb, I'm still struggling
<g> ... Not intuitive at all.

Cheers. :eek:D
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

On Sun, 25 Mar 2007 16:44:11 +0200, "Doug Robbins - Word MVP"

If you want to remove the two spaces between the initial and the
name, try "([A-Z]{1}.) ([A-z']{1,})"

[snip]

I give up. This worked in a test file but when I added it in to the
main clean up macro, it didn't. When I took out the space between the
\1 and \2, just like in the original macro, it at least took out the
space between the two initials but left the two spaces after ...
<sigh>.

Well, go figure. I have errands to run so maybe when I come back I'll
tackle it again and maybe I'll stumble over what's up with this one.
 
S

StargateFanFromWork

StargateFan said:
On Mon, 26 Mar 2007 10:14:30 +0300, "Graham Mayor"
[snip]
([A-Z].)[<space>]{2}
replace with
\1<space>
however, it makes no account for whatever else you might have in your
document. This will remove the extra space from any sentence that ends in
a
capital letter and full stop/period - which will include initials.

[snip]

Actually, I don't see the problem. Once I figure out how all the brackets,
etc., etc., work, it would be easy enough to run the corrections through so
that the correct form of double spaces between sentences achieved. Then
easy to go through and correct

<space><1 letter>.<2 spaces><word>
to 1 space in between, and any variation for multiple initials,
<space><1 letter>.<1 letter>.<2 spaces><word>

etc., etc.

There shouldn't be more than some cursory manual editing in the end if I do
the macro right. But I have to get used to all those wildcards and such.

Thanks. :eek:D
 
G

Graham Mayor

If you are going to keep double spaces between sentences, for some bizarre
reason, then if you want to remove them from names, which may have one or
two initials then you are going to have to create search separately strings
for one or two initials or run the same search twice to catch the one
initial names then the two initial names (more times if you may have names
with three or more initials), because the search resumes from the place it
last searched.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
StargateFan said:
On Mon, 26 Mar 2007 10:14:30 +0300, "Graham Mayor"
[snip]
([A-Z].)[<space>]{2}
replace with
\1<space>
however, it makes no account for whatever else you might have in
your document. This will remove the extra space from any sentence
that ends in a
capital letter and full stop/period - which will include initials.

[snip]

Actually, I don't see the problem. Once I figure out how all the
brackets, etc., etc., work, it would be easy enough to run the
corrections through so that the correct form of double spaces between
sentences achieved. Then easy to go through and correct

<space><1 letter>.<2 spaces><word>
to 1 space in between, and any variation for multiple initials,
<space><1 letter>.<1 letter>.<2 spaces><word>

etc., etc.

There shouldn't be more than some cursory manual editing in the end
if I do the macro right. But I have to get used to all those
wildcards and such.
Thanks. :eek:D
 

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