如何在不使用选择的情况下更改当前段落的格式 [英] How to change format of current paragraph without using Selection

查看:44
本文介绍了如何在不使用选择的情况下更改当前段落的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,但没有使用 Selection.

I have the code below without using Selection.

Sub Format paragraph()

Dim wdDoc As Document

    With wdDoc.Range.Find 
       .Font.Size = 12
       .Text = "?" 
       .Execute 
    End With
End Sub

当找到字体大小=12的字符时,如何更改当前段落的格式?例如:

When the character with font size = 12 is found, how can I change the format of the current paragraph? for example:

wdDoc.Paragraph(current).Font.Size = 14

wdDoc.Paragraph(current).Font.Color = wdBlue

感谢您的帮助.

推荐答案

诀窍是使用特定的 Range 对象,该对象可用于访问其父"段落.当 Find.Execute 成功时,被搜索的 Range 包含找到的项目(与选择跳转到找到的项目相同).例如:

The trick is to work with a specific Range object, which can be used to access its "parent" paragraph. When Find.Execute is successful, the Range being searched contains the found item (same as the selection jumps to the found item). For example:

Sub Format paragraph()
  Dim rng as Range, para as Paragraph
  Dim wdDoc As Document

  Set wdDoc = ActiveDocument. 'Missing in code in question...
  Set rng = wdDoc.Content 'Content returns the Range
    With rng.Find 
       .Font.Size = 12
       .Text = "?" 
       If .Execute = True Then
         Set para = rng.Paragraphs(1)
         para.Font.Size = 14
         para.Font.Color = wdBlue
       End If
    End With
End Sub

这篇关于如何在不使用选择的情况下更改当前段落的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆