Fibnd and Replace

M

Maria

I'm a word processor in a law office at which some of the
secretaries REFUSE to work with automatic numbering. They
often bring in very lengthy documents with edits that
necessitate the renumbering of paragraphs--with the
request, of course, that no automatic numbering be used.
Is there a single Find and Replace action that would
increase each succeeding paragraph number by, say, 2 or 3?

Thanks for being the lifesavers you've proved to be!
 
T

TF

Maria

Well I can understand why the secretaries have refused to use Word
numbering: it is a real dogs breakfast. However, get them all to go to the
link below and click on the Numbering TAB and read the first document
(Word's Numbering Explained) which will give them an insight into how it
works and why they keep screwing it up. There are also several other useful
tips on how to use and sort numbering problems too.

--
Terry Farrell - Word MVP
http://word.mvps.org/

: I'm a word processor in a law office at which some of the
: secretaries REFUSE to work with automatic numbering. They
: often bring in very lengthy documents with edits that
: necessitate the renumbering of paragraphs--with the
: request, of course, that no automatic numbering be used.
: Is there a single Find and Replace action that would
: increase each succeeding paragraph number by, say, 2 or 3?
:
: Thanks for being the lifesavers you've proved to be!
:
:
 
M

Mark Tangard

And if they dig in their heels and still refuse, then yes, assuming the
document's structure is extremely regular and predictable, a macro can
be used to insert new, properly sequenced nonautomatic numbers. In that
case post back with full details on the paragraphing.
 
K

Klaus Linke

Mark Tangard said:
And if they dig in their heels and still refuse, then yes, assuming
the document's structure is extremely regular and predictable, a
macro can be used to insert new, properly sequenced nonautomatic
numbers. In that case post back with full details on the paragraphing.


With the built-in commands ToolsBulletsNumbers, ToolsNumberListDefault, and
ToolsBulletListDefault you don't even have to write your own macros. These
old commands insert numbers or bullets as text.

The ToolsBulletsNumbers dialog lets you add or remove numbers or bullets,
change the start value or the numbering scheme.
(Look in Tools > Customize > Commands tab, All Commands, and drag them into
a toolbar).
The ToolsNumberListDefault and ToolsBulletListDefault buttons insert the
proper number/bullet for the current list.

Regards,
Klaus
 
M

Mark Tangard

Once again, Klaus, you know the most unusual things!! And I
never would've assumed it'd be smart enough to recognize and
repair nonautomatic numbers.

MT (reaching for the 'kick me' sign for having spent an hour
last year writing the macro to achieve what ToolsBulletsNumbers
already does).
 
M

Maria

Hi, Klaus,

Sounds as if your ToolsBulletsNumbers suggestion strikes
a happy medium. Surely they can handle that small amount
of automation!

Just to satisfy my own curiosity, though, does Find and
Replace have a way of finding a number and replacing it
with an increased amount? Or would that only be possible
with a written macro?

I'm trying to study beginning VBA on my own, but the gaps
in my knowledge of it are appalling. So far I've learned
more from you and the others on this site than I have
from books!

Thanks again, Klaus and all, for being right there with
help.
 
K

Klaus Linke

Just to satisfy my own curiosity, though, does Find and
Replace have a way of finding a number and replacing it
with an increased amount? Or would that only be possible
with a written macro?

You'd need a macro. With "hard numbers", you might be able to use the
ToolsBulletsNumbers dialog to get the current number, and increase it by a
given amount... so you could write a macro pretty easily that works with any
numbering scheme:

' to increase all numbers in the selection by 1
' (independent of numbering scheme)
Dim myPara As Paragraph
Dim myRange As Range
Set myRange = Selection.Range.Duplicate
For Each myPara In myRange.Paragraphs
myPara.Range.Select
With Dialogs(wdDialogToolsBulletsNumbers)
.StartAt = .StartAt + 1
.Execute
End With
Next myPara
myRange.Select

But if you use the dialog anyway, it'd be easier to select the paragraphs
and change the start value.

Greetings,
Klaus
 
K

Klaus Linke

Once again, Klaus, you know the most unusual things!!

Well, I only discovered it about a year ago, by accident.
I did use Word2, but I guess I never tried the dialog back then.

And I still haven't figured out how you're supposed to do outline numbering
with this dialog. With some settings, {AutoNumLgl} fields are inserted
instead of hard text...
If there's some time, I'll get out Woody's "Hacker's guide", to learn more
about it.

Greetings,
Klaus
 
G

Guest

Hi, Klaus,

Thank you, thank you, thank you!
-----Original Message-----

You'd need a macro. With "hard numbers", you might be able to use the
ToolsBulletsNumbers dialog to get the current number, and increase it by a
given amount... so you could write a macro pretty easily that works with any
numbering scheme:

' to increase all numbers in the selection by 1
' (independent of numbering scheme)
Dim myPara As Paragraph
Dim myRange As Range
Set myRange = Selection.Range.Duplicate
For Each myPara In myRange.Paragraphs
myPara.Range.Select
With Dialogs(wdDialogToolsBulletsNumbers)
.StartAt = .StartAt + 1
.Execute
End With
Next myPara
myRange.Select

But if you use the dialog anyway, it'd be easier to select the paragraphs
and change the start value.

Greetings,
Klaus


.
 
L

Larry

I love Word's undocumented built-in commands. It makes dealing with
Word like archeology.

Larry
 
R

ratwod

I need to increment a bunch of numbers in a portion of a document.

E.g.: "13" --> "14" "20" --> "21" These are not paragraph numbers.

Is there a macro to do this
 
K

Klaus Linke

ratwod said:
I need to increment a bunch of numbers in a portion of a document.

E.g.: "13" --> "14" "20" --> "21" These are not paragraph numbers.

Is there a macro to do this?


Hi ratwood,

Below is a simple macro, which increments all numbers in the current
selection by 1.

You could make it safer by adding some restrictions (increment only numbers
between 1 and 100, or only numbers that aren't followed or preceeded by a
(decimal) dot...

Greetings,
Klaus

Sub IncrementInSelection()
' select some text containing numbers,
' then start the macro
Dim rngFind As Range
Set rngFind = Selection.Range.Duplicate
rngFind.Find.ClearFormatting
With rngFind.Find
.Text = "<[0-9]@>"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
While .Execute
rngFind.Text = _
Trim(Str(Val(rngFind.Text) + 1))
rngFind.Collapse (wdCollapseEnd)
rngFind.End = Selection.End
Wend
End With
End Sub
 
B

Bruce Brown

Klaus

Hate to be the bearer of bad news but this one causes an endless loop:

Sub IncrementInSelection()
' select some text containing numbers,
' then start the macro
Dim rngFind As Range
Set rngFind = Selection.Range.Duplicate
rngFind.Find.ClearFormatting
With rngFind.Find
.Text = "<[0-9]@>"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
While .Execute
rngFind.Text = _
Trim(Str(Val(rngFind.Text) + 1))
rngFind.Collapse (wdCollapseEnd)
rngFind.End = Selection.End
Wend
End With
End Sub

The problem appeared to be with these two lines:

rngFind.Collapse (wdCollapseEnd)
rngFind.End = Selection.End

The changes below fixed it. Not sure quite why, but you don't need the
Trim(Str(Val(R.Text) + 1). R.Text = R.Text + 1 will do the trick.

Sub IncrementInSelectionPartII()
' select some text containing numbers,
' then start the macro
Dim R As Range
Set R = Selection.Range.Duplicate
With R.Find
.Text = "<[0-9]@>"
.MatchWildcards = True
While .Execute
R.Text = Trim(Str(Val(R.Text) + 1))
R.Collapse wdCollapseEnd
Wend
End With
End Sub

- Bruce
 
R

ratwod

Thanks very much.

EXCEPT (sorry)

if the number is the first in a selection, the macro gets into an
infinite loop.

E.g:

A horse has 4 legs. 4 legs has a horse.<--Works great

4 legs has a horse. A horse has 4 legs.<--macro bombs
 
R

ratwod

Thank you very much. This problem has been a pain in my a** for years.

One slight modification:

Can there be a dialog box that asks, "How much do you want to incremen
this by?" and then the number inputted is the number used to incremen
the numbers in the text?

Thanks again. I'ld buy you a pint of Bass if I could
 
K

Klaus Linke

Hi ratwood,

Sorry for that... Didn't test with a text that starts with a number.
You can use Bruce's macro if you want to increment numbers in the whole
document, else see the version below.


Hi Bruce,

Thanks for spotting the problem, and fixing the macro ... and kudos for
simplifying the code by making use of implicit conversion!
It looks like the Selection gets clobbered if you insert text right at the
beginning or end of it.

Your macro will replace numbers in the whole (main) document.
If you just want to replace in the Selection:

Sub IncrementInSelectionPartIII()
' select some text containing numbers,
' then start the macro
Dim R As Range
Dim R_old As Range
' Using R_old in case the Selection gets destroyed
Set R_old = Selection.Range.Duplicate
Set R = R_old.Duplicate
With R.Find
.Text = "<[0-9]@>"
.MatchWildcards = True
Do While .Execute
R.Text = R.Text+ 1
R.Collapse wdCollapseEnd
' Selection ends with a number?
If R.End < R_old.End Then
R.End = R_old.End
Else
R_old.End = R.End
Exit Do
End If
Loop
End With
' To reset the selection in case it got clobbered:
R_old.Select
End Sub

Hope it works as advertised this time :)
Perhaps the code could be simplified a bit by using a bookmark instead of a
range.

Regards,
Klaus
 
K

Klaus Linke

Can there be a dialog box that asks, "How much do you want to increment
this by?" and then the number inputted is the number used to increment
the numbers in the text?

Add at the top of the macro:

Dim iAdd As Long
iAdd = InputBox("How much ...?", "Increment:")

Then, use
R.Text = R.Text+ iAdd
further down.

Thanks again. I'ld buy you a pint of Bass if I could.

Make it a virtual pint then :)
Cheers, Klaus
 

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