this vb code correctly removes numbering but also removes bullet points - i want to keep only the first functionality
Sub a_usunNumeracjeOproczNaglowkow()
Dim doc As Document
Dim para As Paragraph
Dim i As Long
Dim totalParas As Long
Dim styleNameToCheck As String
Dim targetStyle As Variant
Dim targetStyleNames As Variant
Set doc = ActiveDocument
' --- Maximum performance settings ---
Dim originalScreenUpdating As Boolean
Dim originalDisplayAlerts As WdAlertLevel
originalScreenUpdating = Application.ScreenUpdating
originalDisplayAlerts = Application.DisplayAlerts
Application.ScreenUpdating = False
Application.DisplayAlerts = wdAlertsNone
'--------------------------------------
On Error GoTo ErrorHandler
totalParas = doc.Paragraphs.Count
' Define the style names from which numbering should be removed
' Add any other style names if necessary (e.g., "List Paragraph")
targetStyleNames = Array("Normal", "Normalny") ' Using localized name for Polish Word
' Process paragraphs in reverse order. This is generally safer if
' operations might delete or merge paragraphs, though RemoveNumbers usually doesn't.
For i = totalParas To 1 Step -1
Set para = doc.Paragraphs(i)
' Get the style name of the current paragraph
' Using .NameLocal to get the displayed style name (e.g., "Normalny")
On Error Resume Next ' In case .Style or .NameLocal is problematic for a specific paragraph
styleNameToCheck = para.Style.NameLocal
If Err.Number <> 0 Then
styleNameToCheck = "" ' Reset if there was an error getting the style name
Err.Clear
End If
On Error GoTo ErrorHandler ' Restore normal error handling for the rest of the loop
' Check if the paragraph's style is one of the target styles
For Each targetStyle In targetStyleNames
If LCase(styleNameToCheck) = LCase(CStr(targetStyle)) Then
' If the style matches, and it actually has list formatting, remove the numbering.
If para.Range.ListFormat.ListType <> wdListNoNumbering Then
para.Range.ListFormat.RemoveNumbers
End If
Exit For ' Style matched, no need to check other target styles for this paragraph
End If
Next targetStyle
Next i
CleanExit:
' Restore original settings
Application.ScreenUpdating = originalScreenUpdating
Application.DisplayAlerts = originalDisplayAlerts
If Err.Number = 0 Then
MsgBox "Usunięto numerację", vbInformation
End If
Exit Sub
ErrorHandler:
MsgBox "Błąd: " & Err.Description, vbExclamation
Resume CleanExit ' Go to cleanup code
End Sub