【问题标题】:Function that modify text on lists push the last element out of the list修改列表文本的函数将最后一个元素推出列表
【发布时间】:2015-04-16 21:41:39
【问题描述】:
我有这个程序可以将“<OK>”添加到列表中的红色元素,但它会推送列表中最后一个元素
Sub Rojo()
Dim lista As Integer
Dim para As Paragraph
For Each para In ActiveDocument.ListParagraphs
If para.Range.Font.ColorIndex = wdRed Then
para.Range.Text = "<OK> " + para.Range.Text
End If
Next para
如果我有清单:
变成:
红色文字
我该怎么办?
【问题讨论】:
标签:
list
vba
ms-word
word-2010
【解决方案1】:
添加此元素后,元素将再次列出,但在新列表中。现在我需要把它推到以前的列表中。 (Hecho 是一个全局布尔值)
Sub Rojo()
Dim p As Paragraph
Dim iTotalParas As Integer, iParaCounter As Integer
Comienzo:
If hecho = False Then
iTotalParas = ActiveDocument.Paragraphs.Count
For iParaCounter = 1 To iTotalParas
' For Each p In ActiveDocument.Paragraphs
Set p = ActiveDocument.Paragraphs(iParaCounter)
If p.Range.Font.ColorIndex = wdRed Then
'Mi cosecha
p.Range.Text = "<OK>" + p.Range.Text
If ActiveDocument.Paragraphs(iParaCounter).Range.ListFormat.ListType = 0 Then
ActiveDocument.Paragraphs(iParaCounter).Range.ListFormat.ApplyOutlineNumberDefault
End If
End If
' Next p
Next iParaCounter
hecho = True
'Si ya la hemos ejecutado y volvemos a usarla, avisa antes y controlamos la repetición
Else
If MsgBox("Ya has ejecutado esta macro boniato!" & Chr(13) & "¿Quieres ejecutarla de nuevo?", vbYesNo, "User Input") = vbYes Then
hecho = False
GoTo Comienzo
Else
hecho = True
End If
End If
End Sub
已编辑::::::::========
好吧,我做的越多,我学到的就越多。只需将 p.Range.Text = "" + p.Range.Text 更改为 p.Range.InsertBefore("OK")