Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2013, 03:39 AM
amitkapoor amitkapoor is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 64bit
Novice
Replace each heading with a unique numeric value
 
Join Date: May 2013
Posts: 4
amitkapoor is on a distinguished road
Default Replace each heading with a unique numeric value

I have a huge Word document. I want to replace all of its headings with a unique numeric value, say, 10001,10002,10003, and so on. So maybe the heading is h1 or h2 or h3 or h4 or other higher levels, every heading will get replaced with a numeric value that will be unique throughout the document.



Can anyone please help? This is urgent.
Reply With Quote
  #2  
Old 05-05-2013, 04:39 AM
macropod's Avatar
macropod macropod is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You can do this simply enough by applying multi-level list numbering to the headings and, if necessary for your purposes, using a wildcard Find/Replace to delete each heading's text, where:
Find = *
Replace = ^p
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-05-2013, 05:34 AM
amitkapoor amitkapoor is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 64bit
Novice
Replace each heading with a unique numeric value
 
Join Date: May 2013
Posts: 4
amitkapoor is on a distinguished road
Default

Thank you. But this will not help.

Applying numbering can be done but that will never become part of the heading when I try to use, say Find and Replace, or import the document to another software. The numbering is Field Codes in place. I want the heading's text to be replaced with numbers like 10001, 10002, and so on.

Also, * and ^p doesn't work. Note that I want to change the text in headings only. Can you suggest something else with these details. Note that I want to do this for all heading levels in the document.
Reply With Quote
  #4  
Old 05-05-2013, 07:34 AM
macropod's Avatar
macropod macropod is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, what are the rules as to how each heading's text is to be numbered? Are all Heading 1 paras to start at 10001, Heading 2 to start at 20001, and so on, for example, or something else?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-05-2013, 08:29 AM
amitkapoor amitkapoor is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 64bit
Novice
Replace each heading with a unique numeric value
 
Join Date: May 2013
Posts: 4
amitkapoor is on a distinguished road
Default

No rules at all. Headings should get just a unique integer value and better if it is more than 10000. So if the flow is
h1, h2, h2, h3, h1, h2, h3, h4, h5, h6, h2, h3.... then the headings should now be 10001, 10002, 10003, 10004, 10005, 10006, and so on. The numeric value can be any but better if it is at least > 100 or 1000.
Reply With Quote
  #6  
Old 05-05-2013, 04:16 PM
macropod's Avatar
macropod macropod is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You can do this with a fairly simple macro:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Prgrph As Paragraph, i As Long, Rng As Range
For Each Prgrph In ActiveDocument.Paragraphs
  If Prgrph.Style Like "Heading #" Then
    i = i + 1
    Set Rng = Prgrph.Range
    Rng.End = Rng.End - 1
    Rng.Text = 10000 + i
  End If
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-06-2013, 02:15 AM
amitkapoor amitkapoor is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 64bit
Novice
Replace each heading with a unique numeric value
 
Join Date: May 2013
Posts: 4
amitkapoor is on a distinguished road
Default

Thank you so much. It worked but with error:Error 6028: The Range Cannot be Deleted?
I get an option to debug in the error window. I tried changing range from 10000 to 100000 in the code but still the same error. Though the error comes, almost 95% of the headings are converted just fine. Notice that the document has almost 3500 headings.
Reply With Quote
  #8  
Old 05-06-2013, 03:29 AM
macropod's Avatar
macropod macropod is offline Replace each heading with a unique numeric value Windows 7 64bit Replace each heading with a unique numeric value Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I suggest you check the offending heading. Comment-out or delete:
Application.ScreenUpdating = False
and insert:
Rng.Select
before:
Rng.Text = 10000 + I
With these changes, the code should fail with the problem range selected. I suspect you'll find it's either an empty paragraph or there is something else non-standard about it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
headings numeric



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace each heading with a unique numeric value How to add space between heading number and heading text Dr Wu Word 4 07-15-2018 03:52 AM
Replace each heading with a unique numeric value How to Restore Heading 1, Heading 2, etc. within a Word Document cheech1981 Word 9 01-11-2017 02:14 AM
Challenging Heading Edit with Find Replace binar Word 10 12-23-2012 08:16 PM
Replace each heading with a unique numeric value Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM
Replace each heading with a unique numeric value Styles: Heading 4 stuck at same heading number Hallet Word 1 05-31-2012 02:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft