参考:Object model (Word VBA reference)


序号 类名称  

功能说明

  语法 & 举例
01 Selection  

====<<<< Description >>>>====

代表窗口或窗格中的当前所选内容。所选内容代表文档中选定(或突出显示)的区域,如果文档中没有选定任何内容,则代表插入点。每个文档窗格只能有一个 Selection 对象,并且在整个应用程序中只能有一个活动的 Selection 对象。
----------------------------------------------------------------------------------

====<<<<  Methods >>>>====

◈ Expand (Unit):扩展指定的区域或所选内容。返回添至该区域或所选内容的字符数。
----------------------------------------------------------------------------------

====<<<< References >>>>====

参考:python文件打开方式详解——a、a+、r+、w+区别

   
02 Selection.Expand()  

====<<<< Description >>>>====

扩展指定的区域或所选内容。返回添至该区域或所选内容的字符数。
----------------------------------------------------------------------------------

====<<<< Syntax >>>>====

Selection.Expand (Unit)
----------------------------------------------------------------------------------

====<<<< Parameters >>>>====

◈ Unit:可选。一个 WdUnits 常量,代表要扩大范围的度量单位。默认值是wdWord 。
  wdLine:5,一行。
  wdParagraph:4,一个段落。
  wdSentence:3,一个句子。
  wdWord:2,一个单字。
  wdCharacter:1,一个字符。

  wdCell:12,一个单元格。
  wdColumn:9,一列。
  wdRow:10,一行。
  wdTable,15,一个表格。

 

Sub Yellow()
'选定光标所在行
Selection.Expand Unit:=wdLine
'选定行背景色设置
Selection.Range.HighlightColorIndex = wdYellow
'选定行字体颜色设置
Selection.Range.Font.ColorIndex = wdRed
End Sub
         
Sub 删除答案()
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorRed
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = wdColorYellow
With Selection.Find
.Text = "(*).您选择了:(*)"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
           
Sub test()

    Dim i As Integer
Dim text As String
Set paras = ActiveDocument.Range.Paragraphs
'For i = paras.Count To 1 Step -1
' text = ActiveDocument.Range.Paragraphs(i).Range.text
' If ActiveDocument.Range.Paragraphs(i).Range.HighlightColorIndex = wdNoHighlight Then
' MsgBox text
' End If
'Next Application.ScreenUpdating = False '关闭屏幕刷新 '通过遍历将没有高亮的用粉色标记,如果直接操作文本,会出错
For i = 1 To paras.Count
text = ActiveDocument.Range.Paragraphs(i).Range.text
If ActiveDocument.Range.Paragraphs(i).Range.HighlightColorIndex = wdNoHighlight Then
ActiveDocument.Range.Paragraphs(i).Range.Font.ColorIndex = wdPink
End If
Next '将粉色的全部替换为空
Selection.Find.ClearFormatting
Selection.Find.Font.ColorIndex = wdPink
With Selection.Find
.text = "*"
.Replacement.text = ""
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll End Sub Sub test2() Dim i As Integer
Dim para As Paragraph
Set paras = ActiveDocument.Range.Paragraphs
Application.ScreenUpdating = False '关闭屏幕刷新 '通过遍历将没有高亮的用粉色标记,如果直接操作文本,会出错
For Each para In paras
If para.Range.HighlightColorIndex = wdNoHighlight Then
para.Range.text = ""
End If
Next End Sub

参考:word的vba问题,批量删除文本,高手支招!

【330】word - VBA 相关实现的更多相关文章

  1. 处理Selection对象和Range对象——Word VBA中重要的两个对象

    处理Selection对象和Range对象——Word VBA中重要的两个对象 Word 开发人员参考Selection 对象代表窗口或窗格中的当前所选内容.所选内容代表文档中选定(或突出显示)的区域 ...

  2. Delphi 运行Word VBA 宏 删除软回车

    Sub 整理网页()'整理网页:删除软回车.删除空白段.使段落文字两端对齐Selection.WholeStory        Selection.Find.ClearFormatting    S ...

  3. vba 相关

    返回当前默认文件路径: Application.DefaultFilePath 返回应用程序完整路径 Application.Path 返回当前工作薄的路径 ThisWorkbook.Path App ...

  4. VBA相关

    --能否彻底隐藏某行或某列 用代码隐藏列,将其放在Private Sub Worksheet_SelectionChange(ByVal Target As Range)Columns(1).Enti ...

  5. 论文word排版相关插件

    其中包括破解版的MathType.EndNote X7以及Aurora 链接:http://pan.baidu.com/s/1boRZTmf 密码:a6ai

  6. word break相关问题的解法

    https://leetcode.com/problems/word-break/?tab=Description 以及 https://leetcode.com/problems/concatena ...

  7. word vba 1 页面视图

  8. Excel VBA 操作 Word(入门篇)

    原文地址 本文的对象是:有一定Excel VBA基础,对Word VBA还没有什么认识,想在Excel中通过VBA操作Word还有困难的人.   一.新建Word引用 需要首先创建一个对 Word A ...

  9. Word 借助VBA一键实现插入交叉引用

    最近写论文的时候,经常需要向上或向下插入题注的交叉引用,word 自带的界面往往需要操作多次,才能实现插入.而平时使用较多的只是交叉引用附近的题注,比如如图1.1所示,在图1.1中等,距离较远的引用则 ...

随机推荐

  1. python socket 编程(TCP与UDP)

    实验环境:python2 一.TCP编程 1.建立TCP服务器 ①创建TCPServer.py文件 ②编写服务器代码 1)创建socket对象,调用socket构造函数 2)绑定ip端口(IP号和端口 ...

  2. @pathVariable的作用

    //url中的id 可通过@pathVariable绑定到函数的参数中

  3. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  4. 改造 Ace Admin 模板的 ace_tree 组件的 folderSelect 样式

    *注:我用的Ace Admin版本为1.3.4 Ace Admin 是一个轻量,功能丰富,HTML5.响应式.支持手机及平板电脑上浏览的优秀管理后台模板. 关于tree的使用,html文件夹下tree ...

  5. LR 解压缩函数(wgzMemDecompressBuffer)失败 Code=-5

    用LR做压力测试的时候有时会报错 “解压缩函数(wgzMemDecompressBuffer)失败 返回Code=-5”. Google了一把,也没有解决掉. 因为有些脚本运行时没有问题,感觉可能和请 ...

  6. IOS中UITableViewCell使用详解

    IOS中UITableViewCell使用详解 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(N ...

  7. 新手学Appium_Python_Client

    原文转自http://blog.sina.com.cn/s/blog_68f262210102v538.html 一,Appium_Python_Client的安装 推荐使用pip安装 pip ins ...

  8. [LOJ535]「LibreOJ Round #6」花火

    loj description 给你一个排列\(h_i\),你需要交换任意两个位置上的数使得交换后排列的逆序对数最少. \(n \le 3\times 10^5\) sol 首先可以发现,如果交换两个 ...

  9. Yocto使用小技巧

    1. 借助Yocto编译模块 SRC := mytest obj-m := $(SRC).o KDIR := /media/Yocto/build/tmp/work/poky-linux/linux- ...

  10. streamsets excel 数据处理

    streamsets 有一个directory的origin 可以方便的进行文件的处理,支持的格式也比较多,使用简单 pipeline flow 配置 excel 数据copy 因为使用的是容器,会有 ...