I'm trying to write a routine to enable me to continue numbering including style from the previous slide. I got half way there and got stuck.
First thing is I'm always getting the same bullet.type regardless of the style that is applied on the previous slide.
Secondly, I can't figure out to identify the last numbered line and its bullet style on the previous slide. I wrote some pseudocode and left it at that as I tried to get working but was stuck at the previous post. I would need help on how to test if a line is bulleted and what type of bullet and style it is.
Code follows.
Thanks in advance.
Sub ContinueNumbering()
Dim oSlide As slide
Dim oShape As Shape
Dim PreviousBulletType As Long
Dim i As Single
'on err goto err_handler
If ActiveWindow.Selection.Type = ppSelectionNone Then GoTo err_handler
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then GoTo err_handler
Set oShape = ActiveWindow.Selection.ShapeRange(1)
Set oSlide = Application.ActiveWindow.View.slide
If oSlide.SlideIndex = 1 Then
MsgBox "No previous slide.", vbCritical, "Error"
Exit Sub
End If
With ActivePresentation.Slides(oSlide.SlideIndex - 1).Shapes(oShape.Name)
With .textFrame.textRange.ParagraphFormat
PreviousBulletType = .bullet.Type
MsgBox .bullet.Type
End With
End With
'' //////////////////////////////////////
'' Pseudo code from here on
''///////////////////////////////////////
'' For...next lines in previous slide
'' test if bulleted or numbered
'' if first line with bullet found is numbered
'' count the number of numbers
'' style to apply = bullet style of last shape on previous slide
''
'' apply bullet style to selected shape, textbox or placeholder
''
With ActiveWindow.Selection.ShapeRange(1)
With .textFrame.textRange.ParagraphFormat.bullet
.Type = ppBulletNumbered
.StartValue = UserInput
End With
End With
Exit Sub
err_handler:
MsgBox "Please select a single shape.", vbCritical, "Error"
On Error Resume Next
End Sub
The code you were using was giving as result the number of the first item in the bullet list, I amended as per below to count the paragraphs (i.e. in this case the lines) and continue the numbered list to the selected shape. I tested it and it works unless you add text after the previous bulleted list (that is, if at the end of the list there is not a numbered list item, it will not work). Also, there should not be empty bullet number lines in the previous list or they will be counted as well.
Sub ContinueNumbering()
Dim oSlide As slide
Dim oShape As Shape
Dim PreviousBulletType As Long
Dim i As Integer
Dim ppSelectionTextRange As TextRange
Dim bulletNum As Long
'on err goto err_handler
If ActiveWindow.Selection.Type = ppSelectionNone Then GoTo err_handler
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then GoTo err_handler
Set oShape = ActiveWindow.Selection.ShapeRange(1)
Set oSlide = Application.ActiveWindow.View.slide
If oSlide.SlideIndex = 1 Then
MsgBox "No previous slide.", vbCritical, "Error"
Exit Sub
End If
With ActivePresentation.Slides(oSlide.SlideIndex - 1).Shapes(oShape.Name)
For i = 1 To .TextFrame.TextRange.Paragraphs.Count 'here the number of lines is counted
i = .TextFrame.TextRange.Paragraphs.Count
Next i
With .TextFrame.TextRange.Paragraphs(i)
bulletNum = .ParagraphFormat.Bullet.Number 'here the bullet number is found
End With
End With
With ActiveWindow.Selection.ShapeRange(1)
With .TextFrame.TextRange.ParagraphFormat.Bullet
.Type = ppBulletNumbered
.StartValue = bulletNum + 1 'here the numbering is continued
End With
End With
Exit Sub
err_handler:
MsgBox "Please select a single shape.", vbCritical, "Error"
On Error Resume Next
End Sub