Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2016, 09:20 AM
Ajay2506 Ajay2506 is offline Replacing numbering except for headings Windows 7 64bit Replacing numbering except for headings Office 2013
Novice
Replacing numbering except for headings
 
Join Date: Jun 2016
Posts: 8
Ajay2506 is on a distinguished road
Default Replacing numbering except for headings

Hi,



I have the following program which actually replace all the numbering in the word documents to some other symbol.

Sub ReplaceNumbers()
Dim oPara As Paragraph
Dim r As Range
For Each oPara In ActiveDocument.Paragraphs()
Set r = oPara.Range
If r.ListFormat.ListType = wdListSimpleNumbering Then
r.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
r.InsertBefore Text:="**"
End If
Set r = Nothing
Next
End Sub


The only addition I want in this program is to: It should work for all except the titles with heading 1.

for example if Input is:

1. Heading 1 (in heading 1 style)

1. body text 1
2. body text 2
3. normal text 3

Output should be:

1. Heading 1

** body text 1
** body text 2
** normal text 3

Only numbering and word with heading 1 style should be untouched. Earlier i was trying
ActiveDocument.ConvertNumbersToText

but it is changing the entire document numbering to text.

Thanks in advance.
Reply With Quote
  #2  
Old 06-27-2016, 05:56 PM
Guessed's Avatar
Guessed Guessed is offline Replacing numbering except for headings Windows 10 Replacing numbering except for headings Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I would have expected the Headings to use outline numbering but if you are having problems then try this variation
Code:
Sub ReplaceNumbers()
  Dim oPara As Paragraph
  Dim r As Range
  For Each oPara In ActiveDocument.Paragraphs()
    Set r = oPara.Range
    If r.ListFormat.ListType = wdListSimpleNumbering And r.Style <> "Heading 1" Then
      r.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
      r.InsertBefore Text:="**"
    End If
    Set r = Nothing
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 06-28-2016, 05:28 AM
Ajay2506 Ajay2506 is offline Replacing numbering except for headings Windows 7 64bit Replacing numbering except for headings Office 2013
Novice
Replacing numbering except for headings
 
Join Date: Jun 2016
Posts: 8
Ajay2506 is on a distinguished road
Default It works well, thank you.

Thank you, it worked well. Can we generalised it for all headings. Like, right now it is only for heading 1 if we can make it for any headings ranging from heading 1 to heading 9 all.

Thank you.
Reply With Quote
  #4  
Old 06-28-2016, 06:18 PM
Guessed's Avatar
Guessed Guessed is offline Replacing numbering except for headings Windows 10 Replacing numbering except for headings Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

As I said, the Headings should be using outline numbering if you want the numbers to relate to each other. If this was the case, the original code would have ignored the headings numbers.

Failing that, there are two other potential ways to sort the headings from the rest. Try either of the following in place of the If line:

If r.ListFormat.ListType = wdListSimpleNumbering And Left(r.Style,7) <> "Heading" Then

If r.ListFormat.ListType = wdListSimpleNumbering And r.ParagraphFormat.OutlineLevel < 10 Then
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing numbering except for headings Numbering a part of the headings daanhaeyen Word 3 09-28-2015 12:15 PM
List & headings & numbering problems Vegas Word 2 02-24-2015 03:01 AM
Headings - Levelled Numbering pgrant Word 2 11-28-2013 04:00 PM
Headings and numbering Mart. Word 1 04-05-2012 12:02 PM
Word headings not numbering correctly? rbilleaud Word 4 08-03-2011 08:46 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:59 AM.


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