Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-06-2022, 07:03 PM
jec1 jec1 is offline AutoNumber manual numbered documents Windows 10 AutoNumber manual numbered documents Office 2019
Advanced Beginner
AutoNumber manual numbered documents
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default AutoNumber manual numbered documents

Hi, just following on from Shelley Lou's post with Macropod and others re autonumbering different styled documents.



I attach BEFORE doc and AFTER doc. In the after doc the macro ceases at 3.7 Test for some reason. I tried making the heading longer but it didn't make a difference.

I have been using the macro below from Macropod:

Code:
Sub ApplyHeadingStyles_Auto1Works1()
Application.ScreenUpdating = False
Dim Para As Paragraph, Rng As Range, i As Long, StrTxt As String, bLvl As Boolean
Dim objUndo As UndoRecord: Set objUndo = Application.UndoRecord
With ActiveDocument.Range
  For Each Para In .Paragraphs
    With Para
      Set Rng = .Range.Characters.First
      With Rng
        If .text Like "[0-9(]" Then
          .MoveEndUntil " ", wdForward
          If InStr(.text, vbTab) > 0 Then
            .Collapse wdCollapseStart
            .MoveEndUntil vbTab, wdForward
          End If
          StrTxt = .text: bLvl = False
          .End = .End + 1
          objUndo.StartCustomRecord ("Fmt")
          For i = 1 To 6
            .Style = "Heading " & i
            If .ListFormat.ListString = StrTxt Then
              .text = vbNullString: bLvl = True: Exit For
            End If
          Next
          objUndo.EndCustomRecord
          If bLvl = False Then ActiveDocument.Undo: DoEvents
        End If
      End With
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
Attached Files
File Type: docx Before Doc 1.docx (78.2 KB, 9 views)
File Type: docx After Doc 1 autonumber.docx (80.7 KB, 6 views)
Reply With Quote
  #2  
Old 08-07-2022, 04:49 PM
Guessed's Avatar
Guessed Guessed is offline AutoNumber manual numbered documents Windows 10 AutoNumber manual numbered documents Office 2016
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

It stops working at 3.7 because your document doesn't have a 3.6 heading before it. The preceding heading is 3.5. The (very elegant) code is comparing the expected numbers with the hard coded numbers and if the pattern a match is not identified then it leaves it as is.

Once the expected numbers are broken, it won't start working again until you get to the next parent Heading level.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-07-2022, 11:57 PM
jec1 jec1 is offline AutoNumber manual numbered documents Windows 10 AutoNumber manual numbered documents Office 2019
Advanced Beginner
AutoNumber manual numbered documents
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default

Thank you Guessed.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Word have Autonumber Format (like in FrameMaker)? Luxanais Word 7 05-19-2015 12:57 AM
AutoNumber manual numbered documents Autonumber MS Word template Lpitt56 Word 1 09-22-2011 04:04 PM
need autonumber in my excel file mit Excel 2 06-21-2011 10:56 PM
Match numbered list formatting b/w documents? sbranecki Word 0 09-10-2009 03:12 PM
Reversed Printing of Numbers in Numbered Documents HCM1962 Word 0 09-22-2008 10:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:55 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