我给VBA下的定义:VBA是个人小型自动化处理的有效工具。可以大大提高自己的劳动效率,而且可以提高数据的准确性。我这里专注VBA,将我多年的经验汇集在VBA系列九套教程中。
作为我的学员要利用我的积木编程思想,积木编程最重要的是积木如何搭建及拥有积木。在九套教程中我给出了大量的积木,同时讲解了如何搭建。为了让学员拥有更多的积木,我开始着手这部《VBA即用型代码手册(汉英)》的创作,这部手册约600页,集合约500多个的案例,案例我用汉语和英语同时发布,一方面学员从中可以更好的领会和掌握VBA中用到的一些英语知识,另一方面,大家可以看到各种各样的积木。这部手册是大家学习和工作中的不可多得的实用资料。今日的内容是: VBA即用型代码手册:循环Loops与段落Paragraph
【分享成果,随喜正能量】140 真正厉害的人,从来不说难听的话,因为人心不需要听真话,只需要听好听的话,所以学着做一个有温度且睿智的人。不相为谋,但我照样能心平气和,冷眼相待,我依旧可以风生水起,你所见皆是我,好与坏,我都不反驳。。
第五章 Word 基本代码示例
Word Basic Macro Examples
6 循环Loops
Description
描述
VBA Code
Do Until End of Doc
执行直到文档结束
Do Until ActiveDocument.Bookmarks(“\Sel”) = ActiveDocument.Bookmarks(“\EndOfDoc”)
‘Do Something
Sub
For Each Doc in Docs
对于 Docs 中的每个 Doc
Dim doc As Document
ForEach doc In Documents
‘Do Something
Next doc
Loop Through Paragraphs
循环段落
Sub through Paragraphs
Dim i As Long, iParCount As Long
iParCount = ActiveDocument.Paragraphs.CountFori = 1 To iParCount
ActiveDocument.Paragraphs(i).Alignment = wdAlignParagraphLeft
Next i
7 段落Paragraph
Description
描述
VBA Code
KeepLinesTogether
段落的所有行是否将保持在同一文本框中
Selection.ParagraphFormat.KeepTogether = True
KeepWithNext
下一段是否将保留在与指定段落相同的文本框中
Selection.ParagraphFormat.KeepWithNext = True
Space After
第一行前的间距大小
Selection.ParagraphFormat.SpaceAfter = 12
Space Before
每段最后一行后的间距大小
Selection.ParagraphFormat.SpaceBefore = 0
Align Center
居中对齐
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Align Right
右对齐
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Align Left
左对齐
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Left Indent
左缩进
Selection.ParagraphFormat.LeftIndent = InchesToPoints(3.75)
Right Indent
右缩进
Selection.ParagraphFormat.RightIndent = InchesToPoints(1)
Line Spacing
行间距
With Selection.ParagraphFormat
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing = 12
End With
Loop Through All Paragraphs
循环遍历所有段落
Sub through Paragraphs
Dim i As Long, iParCount As Long
iParCount = ActiveDocument.Paragraphs.CountFori = 1 To iParCount
ActiveDocument.Paragraphs(i).Alignment = wdAlignParagraphLeft
Next i
我20多年的VBA实践经验,全部浓缩在下面的各个教程中: