Replace dash markers in a Word document

I am trying to replace list bullets in a dash text document, basically replacing only the “display icon”, i.e.

Replace the markers from the list below:

  • this is a list item

  • this is another list item

  • one more element

with dash:

is a list item

is another list item

- another element

I'm going to do this using ActiveX in Delphi, but the VB code will do as well, thanks!

+7
source share
3 answers

Inside the Delphi code :

uses ..., ComObj; const wdListNumberStyleBullet = 23; var vMSWord : variant; Doc : Variant; oListTemplate : Variant; oListLevel : Variant; iLoopTemplates, iMaxTemplates: Integer; iLoopLevels, iMaxLevels : Integer; begin try vMSWord := GetActiveOleObject('Word.Application'); vMSWord.Visible := True; Doc := vMSWord.ActiveDocument; iMaxTemplates := Doc.ListTemplates.Count; for iLoopTemplates := 1 to iMaxTemplates do begin oListTemplate := Doc.ListTemplates.Item(iLoopTemplates); iMaxLevels := oListTemplate.ListLevels.Count; for iLoopLevels := 1 to iMaxLevels do begin oListLevel := oListTemplate.ListLevels.Item(iLoopLevels); if (oListLevel.NumberStyle = wdListNumberStyleBullet) and (oListLevel.NumberFormat = UTF8String(#61623)) and (oListLevel.Font.Name = 'Symbol') then // if (oListLevel.NumberStyle = wdListNumberStyleBullet) then begin oListLevel.NumberFormat := UTF8String('-'); oListLevel.Font.Name := 'Arial'; end; end; end; except ShowMessage('Open a Word document before running this method'); end; 

The current IF checks if it is & bull; bullet wih a *

If you do not need this check, comment out this line (if ...) and uncomment the following ...

+5
source

Is that what you are trying?

 Option Explicit '~~> Select the relevant range before running this code Sub Sample() With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1) .NumberFormat = ChrW(61485) .TrailingCharacter = wdTrailingTab .NumberStyle = wdListNumberStyleBullet .NumberPosition = InchesToPoints(0.25) .Alignment = wdListLevelAlignLeft .TextPosition = InchesToPoints(0.5) .ResetOnHigher = 0 .StartAt = 1 .Font.Name = "Symbol" .LinkedStyle = "" End With ListGalleries(wdBulletGallery).ListTemplates(1).Name = "" Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _ ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _ False, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:= _ wdWord10ListBehavior End Sub 

Snapshot

enter image description here

+6
source

Task macro ...

 Dim oListTemplate As ListTemplate Dim oListLevel As ListLevel For Each oListTemplate In ActiveDocument.ListTemplates For Each oListLevel In oListTemplate.ListLevels If oListLevel.NumberStyle = wdListNumberStyleBullet Then With oListLevel .NumberFormat = "-" .Font.Name = "Arial" End With End If Next oListLevel Next oListTemplate 
+4
source

All Articles