kamkwok6
03-09-2022, 11:01 PM
29485
Hi everyone, I really need a help on that.
The first picture is the original source file with all the numbering and style formatting.
2948429485
Ultimately, I would like to copy all the heading number to corresponding paragraph as below.
29483
I did some research and found some related code. And finally successfully adding some pre-set text at the beginning of the paraph with "Normal" Style, however , the second paragraph of that section would not be able to add. I don't know why. which show as below
29482
After that I find another code which show the corresponding level of that para with msg box.
29486
Can you someone can help to merge these function together...
Sub ApplyMultiLevelHeadingNumbers()
Selection.Range.ListFormat.ConvertNumbersToText
End Sub
Sub Demo()
Application.ScreenUpdating = False
Dim Par As Paragraph, Rng As Range
For Each Par In ActiveDocument.Paragraphs
If Par.Style = "Normal" Then
If Rng Is Nothing Then
Set Rng = Par.Range
Else
Rng.End = Par.Range.End
End If
Else
Call RngFmt(Rng)
End If
If Par.Range.End = ActiveDocument.Range.End Then
Call RngFmt(Rng)
End If
Next
Application.ScreenUpdating = True
End Sub
Sub RngFmt(Rng As Range)
If Not Rng Is Nothing Then
With Rng
.End = .End - 1
.InsertBefore "(Sample) "
Set Rng = Nothing
End With
End If
End Sub
Public Sub FindPreviousOutlineLevel()
Dim aNumber As Long
Dim aRange As Word.Range
Set aRange = ActiveDocument.Range(0, Selection.Range.End)
For aNumber = aRange.Paragraphs.Count To 1 Step -1
If ActiveDocument.Paragraphs(aNumber).Range.ParagraphFormat.OutlineLevel _
<> 10 Then
Set aRange = ActiveDocument.Paragraphs(aNumber).Range
With aRange.Find
.MatchWildcards = True
.Text = "<[0-9.-]{1,}"
.Execute
If .Found Then
MsgBox aRange
Else
MsgBox "No Number Found Here: " & aRange
End If
End With
Exit For
End If
Next aNumber
End Sub
Hi everyone, I really need a help on that.
The first picture is the original source file with all the numbering and style formatting.
2948429485
Ultimately, I would like to copy all the heading number to corresponding paragraph as below.
29483
I did some research and found some related code. And finally successfully adding some pre-set text at the beginning of the paraph with "Normal" Style, however , the second paragraph of that section would not be able to add. I don't know why. which show as below
29482
After that I find another code which show the corresponding level of that para with msg box.
29486
Can you someone can help to merge these function together...
Sub ApplyMultiLevelHeadingNumbers()
Selection.Range.ListFormat.ConvertNumbersToText
End Sub
Sub Demo()
Application.ScreenUpdating = False
Dim Par As Paragraph, Rng As Range
For Each Par In ActiveDocument.Paragraphs
If Par.Style = "Normal" Then
If Rng Is Nothing Then
Set Rng = Par.Range
Else
Rng.End = Par.Range.End
End If
Else
Call RngFmt(Rng)
End If
If Par.Range.End = ActiveDocument.Range.End Then
Call RngFmt(Rng)
End If
Next
Application.ScreenUpdating = True
End Sub
Sub RngFmt(Rng As Range)
If Not Rng Is Nothing Then
With Rng
.End = .End - 1
.InsertBefore "(Sample) "
Set Rng = Nothing
End With
End If
End Sub
Public Sub FindPreviousOutlineLevel()
Dim aNumber As Long
Dim aRange As Word.Range
Set aRange = ActiveDocument.Range(0, Selection.Range.End)
For aNumber = aRange.Paragraphs.Count To 1 Step -1
If ActiveDocument.Paragraphs(aNumber).Range.ParagraphFormat.OutlineLevel _
<> 10 Then
Set aRange = ActiveDocument.Paragraphs(aNumber).Range
With aRange.Find
.MatchWildcards = True
.Text = "<[0-9.-]{1,}"
.Execute
If .Found Then
MsgBox aRange
Else
MsgBox "No Number Found Here: " & aRange
End If
End With
Exit For
End If
Next aNumber
End Sub