Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-31-2018, 03:18 AM
ganesang ganesang is offline Windows XP Office 2016
Competent Performer
 
Join Date: Jul 2018
Posts: 103
ganesang is on a distinguished road
Exclamation 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
Reply With Quote
  #2  
Old 07-31-2018, 03:32 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 18,680
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #3  
Old 07-31-2018, 03:55 AM
ganesang ganesang is offline Windows XP Office 2016
Competent Performer
 
Join Date: Jul 2018
Posts: 103
ganesang is on a distinguished road
Default

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....
Reply With Quote
  #4  
Old 07-31-2018, 03:57 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 18,680
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

In that case, change:
.Text = Format(i, "000")
to:
.Text = "00" & i
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 07-31-2018, 04:00 AM
ganesang ganesang is offline Windows XP Office 2016
Competent Performer
 
Join Date: Jul 2018
Posts: 103
ganesang is on a distinguished road
Default

Awesome!!!

Its works fine....
Reply With Quote
  #6  
Old 07-31-2018, 04:04 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 18,680
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #7  
Old 07-31-2018, 04:09 AM
ganesang ganesang is offline Windows XP Office 2016
Competent Performer
 
Join Date: Jul 2018
Posts: 103
ganesang is on a distinguished road
Default

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!!!!
Reply With Quote
Reply

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


All times are GMT -7. The time now is 11:40 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft