search and replace with a numbered reference

G

Guest

I need to do a serarch and replace through a word file, containing deltaview
delete style.

Is there a way I can do a search for these marks and replace them with a
reference code with incrementing numbers for each time the search comes up?

I would then need to call up these references, when needed.
 
G

Greg Maxey

You may be able to adapt this to your needs:

Sub FRWithSequentialNumber()
'Finds a specified text string and replaces with a sequential number
Dim findText As String
Dim startNum
Dim myRange As Range
Set myRange = ActiveDocument.Range
startNum = InputBox("Start sequential numbers at:")
findText = InputBox("Enter text to find")
With myRange.Find
.Text = findText
.MatchWholeWord = True
While .Execute
myRange.Text = Format(startNum, "000")
startNum = startNum + 1
myRange.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
 
G

Guest

Thanks for the quick answer.

I tried pasting this into a macro but could not get it to work.
Sub - funtion was not defined.
 
G

Greg Maxey

Well it works for me.

However, if I understand correctly you want to number sequentially
everytime a defined paragraphs style is used. This example looks for
an marks "Body Text" style. Perhaps you can adapt it to your specific
need:

Sub FRWithSequentialNumber()
Dim startNum
Dim myRange As Range
Set myRange = ActiveDocument.Range
startNum = InputBox("Start sequential numbers at:")
With myRange.Find
.Style = "Body Text"
While .Execute
myRange.MoveEnd wdCharacter, -1
myRange.InsertAfter " " & Format(startNum, "000")
startNum = startNum + 1
myRange.Collapse Direction:=wdCollapseEnd
If myRange.End = ActiveDocument.Range.End - 1 Then Exit Sub
Wend
End With
End Sub
 
G

Guest

Thanks Greg for the quick answer again.

Still having trouble with getting the macro to work (dont know much about
making it)!

On the search, could I search for a style (i.e. deltaview deletion)?

And replace it with a reference (i.e. <dtx1>, <dtx2> etc.) for the next one
and so on?
 
G

Greg Maxey

Have you puthttp://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm the
macro in your document or template project? See:
Have you puthttp://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

If you have a defined style named "deltaview deletion" and you change
this line:
..Style = "Body Text"
to
..Style = "deltaview deletion" then it will "append" a sequential number
to the tail end of each bit of text formatted with the deltaview
deletion style.

If you wanted the existing deltaview deletion text replaced with the
number you could use something like:

Sub FRWithSequentialNumber()
Dim startNum
Dim myRange As Range
Set myRange = ActiveDocument.Range
startNum = InputBox("Start sequential numbers at:")
With myRange.Find
.Style = "deltaview deletion"
While .Execute
myRange.MoveEnd wdCharacter, -1
myRange.Text = "dtx" & startNum
startNum = startNum + 1
myRange.Collapse Direction:=wdCollapseEnd
If myRange.End = ActiveDocument.Range.End - 1 Then Exit Sub
Wend
End With
End Sub
 
G

Guest

Thanks Greg for the information, I now have got it to work (sort of).

Is there a way that the search can see the style and put a reference code
(ie <dtx#>) in for the whole word, sentence, paragraph (ie multi characters,
single characters, formats and including tables?), as it appears throughout
the document.

I would then want to call this reference up to see what was inside (how?).

IS IT POSSIBLE.

Thanks for any help!
 
G

Greg Maxey

A,

If you are using a character style (vice paragraph style) to format
individual bits of text within a larger paragraph, then you might use
this to mark each bit of text,

Sub FRWithSequentialNumber()
Dim startNum
Dim myRange As Range
Set myRange = ActiveDocument.Range
startNum = InputBox("Start sequential numbers at:")
With myRange.Find
.Style = "TestCharSty" 'Replace with your style name.
While .Execute
myRange.Collapse wdCollapseEnd
myRange.Text = " dtx" & startNum
startNum = startNum + 1
myRange.Collapse Direction:=wdCollapseEnd
If myRange.End = ActiveDocument.Range.End - 1 Then Exit Sub
Wend
End With
End Sub

I don't really understand what it is that you are trying to do.
 
G

Guest

I need to take a word file into our system (3B2), when taking word files with
deltaview deletion styles, the text comes in without showing any marks. This
means that we have to delete the style in word or look for the deleted text
on our system.

I am hoping that I can capture the deltaview deletion text in word and
making it easier to import into 3B2. In 3B2 strikethrough text is shown as
<dtx1>, <dtx2> etc., you can show/hide the deleted text on the page.

I am hoping that anyone can help me achieve this.
 

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