我正在尝试用破折号替换word文档中列表的项目符号,基本上只需要替换“渲染图标”,即
从以下列表中替换项目符号:
这是一个列表项
这是另一个列表项
又一项
:
- 这是一个列表项
- 这是另一个列表项
- 还有另一项
我打算在Delphi中使用ActiveX,但是VB代码也可以,谢谢!
答案 0 :(得分:6)
这是你在尝试的吗?
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
<强>快照强>
答案 1 :(得分:5)
在 Delphi 代码中:
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;
当前的 IF 正在检查它是否真的是一个•子弹•
如果您不需要此检查,请注释此行( if ... )并取消注释下一行...
答案 2 :(得分:4)
完成工作的宏......
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