VBA即用型代码手册:Range对象 Range Object
我给VBA下的定义:VBA是个人小型自动化处理的有效工具。可以大大提高自己的劳动效率,而且可以提高数据的准确性。我这里专注VBA,将我多年的经验汇集在VBA系列九套教程中。
作为我的学员要利用我的积木编程思想,积木编程最重要的是积木如何搭建及拥有积木。在九套教程中我给出了大量的积木,同时讲解了如何搭建。为了让学员拥有更多的积木,我开始着手这部《VBA即用型代码手册(汉英)》的创作,这部手册约600页,集合约500多个的案例,案例我用汉语和英语同时发布,一方面学员从中可以更好的领会和掌握VBA中用到的一些英语知识,另一方面,大家可以看到各种各样的积木。这部手册是大家学习和工作中的不可多得的实用资料。今日的内容是: VBA即用型代码手册:Range对象 Range Object
【分享成果,随喜正能量】199 无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事情,而不是让烦恼和焦虑,毁掉你本就不多的热情和定力。心可以碎,手不能停,该干什么干什么在崩溃中继续前行,这才是一个成年人的素养。。
第六章 Word对象及示例
Word Objects and Macro Examples
3 Range对象 Range Object
范围对象 - Word 文档的一部分
Range Object – A part of a Word document
1)范围可以是文档的任何部分,包括整个文档
Range can be any part of document, including entire document:
Dim oRange As Range
Set oRange = ActiveDocument.Content
2) 一个字符
one character
Dim oRange As Range
Set oRange = ActiveDocument.Range.Words(1)
3)将第二段的第一个单词加粗:
In the following example we will make the first word of second paragraph bold:
Dim oRange As Range
Set oRange = ActiveDocument.Paragraphs(2).Range.Words(1)
oRange.Bold = True
4)设置 Range 的文本值:
To set the text value of a Range:
Dim oRange As Range
Set oRange = ActiveDocument.Paragraphs(2).Range.Words(1)
oRange.Text = “Hello ”
提示:注意“Hello”后面的空格。因为单词对象包含一个单词后的空格,只有“hello”我们会得到“Hellonext word”
Tip: Note the space after “Hello”. Because word object includes space after word, with just “hello” we would get “Hellonext word”
5)更改字体
Change font
oRange.Font.Name = "Arial"
6)在消息框中显示特定范围内的字符数
Display in message box number of characters in particular range
MsgBox oRange.Characters.Count
7)在它前面插入一些文本
Insert some text before it
oRange.InsertBefore "this is inserted text "
8)为范围添加注脚
Add a footnote to range
ActiveDocument.Footnotes.Add Range:=oRange, _
Text:="作者:ningzhe"
9) 将其复制到剪贴板
Copy it to clipboard
oRange.Copy
‘通常,您需要更改特定范围所指的内容。 所以你可以修正它的开始和结束
oRange.Start = 5
oRange.End = 50
我20多年的VBA实践经验,全部浓缩在下面的各个教程中: