好吧,可以说我要在Word文档中选定范围内的单词中的某些字符之外的第一个字符大写。我有一个执行类似操作的脚本,但是某些表达式存在问题。在脚本中,我使用Selection.Range.Case,但问题出在URL地址。我想将所有内容都保留为小写,但Selection.Range.Case会将URL链接分解为多个字符串,例如:https,:,//,/等,以此类推。所选文本范围在编号列表中,URL是下一个编号项目之前的最后一件事。有什么解决方案可以将http://或https://之后的所有内容连接到一个字符串,就在下一个编号项目之前吗?谢谢。
答案 0 :(得分:1)
如果选定的文本范围仅在编号列表中,则可以尝试类似的操作
Sub test()
Dim Pg As Paragraph, Pos As Long, Rng As Range
For Each Pg In Selection.Paragraphs
If Not Pg.Range.ListFormat.List Is Nothing Then 'Process only bulleted list
PgTxt = Pg.Range.Text
'Debug.Print PgTxt
Pos = InStr(1, PgTxt, "http")
If Pos <> 1 Then 'bypass if http found at start of List item then no Case Change
If Pos > 1 Then Pos = Pos - 1 'http found some where within the List item
If Pos = 0 Then Pos = Len(PgTxt) ' if http not found in the list Item
Set Rng = ActiveDocument.Range(Pg.Range.Start, Pg.Range.Start + Pos)
Rng.Case = wdTitleWord
End If
End If
Next
End Sub