参考: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. HALCON之喷码OCR识别案例

    一个喷码识别的案例 1 read_image (Image, 'D:/用户目录/Desktop/2.png') 2 3 rgb1_to_gray(Image, Image) 4 5 get_image ...

  2. Xcode 7.0 Could not find developer disk image

    在使用Xcode 7的真机运行的时候, 出现Could not find developer disk image. 解决方法:先关闭Xcode.再从Xcode 6.4中,拷贝8.4 (12H141) ...

  3. Junit4与junt3并存时产生的问题

    目前的项目里用junit写单元测试,使用的是junit4,由于大部分开发之前使用的都是junit3,对junit4还不是很熟悉,所以出现了junit3和4混合使用的情况,导致发生了一些问题,这里列举一 ...

  4. 201621123005《Java程序设计》第十二次作业

    <Java程序设计>第十二次作业 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造 ...

  5. Java中,什么时候用logger.debuge,info,error

    简单的说,就是配合log的等级过滤输出比如,你在开发的时候,要验证一个方法有没有被调用到,为了方便调试,通常会在这个方法开始的时候加一些system.out.但是项目真正发布的时候这些代码通常是要移除 ...

  6. CF1076E:Vasya and a Tree(DFS&差分)

    Vasya has a tree consisting of n n vertices with root in vertex 1 1 . At first all vertices has 0 0 ...

  7. zoj 1828 Fibonacci Numbers

    A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the firs ...

  8. Tiny4412 u-boot分析(3)u-boot 引导内核流程

    在u-boot中,通过bootm命令启动内核.bootm命令的作用是将内核加载到指定的内存地址,然后通过R0.R1.R2寄存器传递启动参数之后启动内核.在启动内核之前需要对环境做一些初始化工作,主要有 ...

  9. Spring Bean单例与线程安全

    一.Spring单例模式及线程安全 Spring框架中的Bean,或者说组件,获取实例的时候都是默认单例模式,这是在多线程开发的时候需要尤其注意的地方. 单例模式的意思是只有一个实例,例如在Sprin ...

  10. 【转】linux中inittab文件详解

    原文网址:http://www.2cto.com/os/201108/98426.html linux中inittab文件详解 init的进程号是1(ps -aux | less),从这一点就能看出, ...