#1
|
|||
|
|||
Need Macro to replace 00R to 001, 002...etc
I have the word document which is contains the number of questions. Each question having the same unique ID called as "00R". In this id "00" is static value and "R" needs to be changed as sequence numbering (1,2,3...etc in text mode) up to number of questions inserted in the document.
Also, "00R" is styled as "Total Points and Test Version". If we using this style, there is no changes made inside of the texts. Moreover, is there any options to popup when run the macro as "enter start number" which is insert the number from the input? Please let me know if anything not clear? Ganesan. G |
#2
|
||||
|
||||
You could use a macro like:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "00R" .Replacement.Text = "" .Forward = True .Format = True .Style = "Total Points and Test Version" .Wrap = wdFindStop .MatchWholeWord = True .MatchWildcards = False .Execute End With Do While .Find.Found i = i + 1 .Text = Format(i, "000") .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True MsgBox i & " instances updated." End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Fantastic!!! its really working...
But even if it is double digits number needs to be retained 00. But this macro changed as 00R to 001, 002...010. I need to retain two zeros (00) even if the question number is 10. So it will be changed as 0010, 0011...etc. thank again for the help.... |
#4
|
||||
|
||||
In that case, change:
.Text = Format(i, "000") to: .Text = "00" & i
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Awesome!!!
Its works fine.... |
#6
|
||||
|
||||
To employ your own starting #, you could insert:
On Error GoTo ErrExit i = CLng(InputBox("Starting #?", , 1)) - 1 after: Dim i As Long and: ErrExit: before: End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Never word to say!!!!!
This one is a really i wanted..... I am just working in word pas 5+ years with formatting related works. I not trying to learn macros detailed. But just used only a record macros. Hereafter, i need to lean lot more from you!!!!! You awesome!!!! |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro/Replace | Summytyme | Word | 4 | 03-31-2017 11:22 AM |
Need Macro to Replace Text | rsrasc | Word VBA | 2 | 11-10-2014 06:26 PM |
Find and Replace Macro | amparete13 | PowerPoint | 3 | 03-11-2014 05:29 AM |
macro or find/replace | JamesVenhaus | Word | 2 | 02-27-2012 03:34 PM |
Find and Replace Macro - A Better Way | Tribos | Word VBA | 0 | 10-08-2008 03:22 AM |