ImageVerifierCode 换一换
格式:DOCX , 页数:38 ,大小:31.03KB ,
资源ID:2900951      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/2900951.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(《循环在WORD+VBA中的应用》.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

《循环在WORD+VBA中的应用》.docx

1、循环在WORD+VBA中的应用循环在WORD VBA 中的应用001在活动文档的开头插入一张 4列3行的表格。For Each.Next结构用于循环遍历表格中的每个单元格。在 For Each.Next结构中,InsertAfter方法用于将文字添至表格单元格(单元格1、单元格2、以此类推)。Sub CreateNewTable()Dim docActive As DocumentDim tblNew As TableDim celTable As CellDim intCount As IntegerSet docActive = ActiveDocumentSet tblNew = _Ra

2、nge:=(Start:=0, End:=0), NumRows:=3, _NumColumns:=4)intCount = 1For Each celTable In Cell & intCountintCount = intCount + 1Next celTableFormat:=wdTableFormatColorful2, _ApplyBorders:=True, ApplyFont:=True, ApplyColor:=TrueEnd Sub002在活动文档中第一张表格的第一个单元格中插入文字。 Cell方法返回单独的 Cell对象。Range属性返回一个 Range对象。Dele

3、te方法用于删除现有的文字, 而InsertAfter方法用于插入文字“ Cell 1,T 。Sub InsertTextInCell()If = 1 ThenWith (1).Cell(Row:=1, Column:=1).Range.Delete.InsertAfter Text:=Cell 1,1End WithEnd IfEnd Sub003返回并显示文档中第一张表格的第一行中每个单元格的内容。Sub ReturnTableText()Dim tblOne As TableDim celTable As CellDim rngTable As RangeSet tblOne = (1)

4、For Each celTable In (1).CellsSet rngTable = (Start:= _End:= - 1)MsgBoxNext celTableEnd SubSub ReturnCellText()Dim celTable As CellDim rngTable As RangeSet tblOne = (1)For Each celTable In (1).CellsSet rngTable =Unit:=wdCharacter, Count:=-1MsgBoxNext celTableEnd Sub004在活动文档的开头插入用制表符分隔的文本,然后将这些文本转换为表

5、格。Sub ConvertExistingText()With .InsertBefore one & vbTab & two & vbTab & three & vbCr.ConvertToTable Separator:=Chr(9), NumRows:=1, NumColumns:=3 End WithEnd Sub005定义一个数组,该数组的元素个数等于文档中第一张表格(假定为 Option Base 1)中的单元格数。For Each.Next结构用于返回每个表格单元格的内容,并将文字指定给相应的 数组元素。Sub ReturnCellContentsToArray()Dim int

6、Cells As IntegerDim celTable As CellDim strCells() As StringDim intCount As IntegerDim rngText As RangeIf = 1 ThenWith .Range intCells =. ReDim strCells(intCells) intCount = 1 For Each celTable In .Cells Set rngText =Unit:=wdCharacter, Count:=-1 strCells(intCount) = rngText intCount = intCount + 1Ne

7、xt celTableEnd WithEnd IfEnd Sub006将当前文档中的表格复制到新文档中。Sub CopyTablesToNewDoc()Dim docOld As DocumentDim rngDoc As RangeDim tblDoc As TableIf = 1 ThenSet docOld = ActiveDocumentSet rngDoc = End:=0)For Each tblDoc InWith rngDoc.Paste.Collapse Direction:=wdCollapseEnd .InsertParagraphAfter.Collapse Direc

8、tion:=wdCollapseEndEnd WithNextEnd IfEnd Sub007显示Documents集合中每个文档的名称。Sub LoopThroughOpenDocuments()Dim docOpen As DocumentFor Each docOpen In DocumentsMsgBoxNext docOpenEnd Sub008使用数组存储活动文档中包含的所有书签的名称。Sub LoopThroughBookmarks()Dim bkMark As BookmarkDim strMarks() As StringDim intCount As IntegerIf 0

9、 ThenReDim strMarks - 1)intCount = 0For Each bkMark InstrMarks(intCount)=intCount = intCount + 1Next bkMarkEnd IfEnd Sub009更新活动文档中的 DATE域。Sub UpdateDateFields()Dim fldDate As FieldFor Each fldDate InIf InStr(1, , Date, 1) ThenNext fldDateEnd Sub010如果名为Filename 的词条是 AutoTextEntries集合中的一部分,则以下示例显示条消息。

10、Sub FindAutoTextEntry()Dim atxtEntry As AutoTextEntryFor Each atxtEntry In If = Filename Then _MsgBox The Filename AutoText entry exists.Next atxtEntryEnd Sub011在第一个表格中添加一行,然后将文本 Cell插入该行。Sub CountCells()Dim tblNew As TableDim celTable As CellDim intCount As IntegerintCount = 1Set tblNew = (1)Set ro

11、wNew = For Each celTable InText:=Cell & intCountintCount = intCount + 1Next celTableEnd Sub012向新文档中添加一个 3行5列的表格,然后在表格的每个单元格中插入数据。Sub NewTable()Dim docNew As DocumentDim tblNew As TableDim intX As IntegerDim intY As IntegerSet docNew =Set tblNew = 3, 5)With tblNewFor intX = 1 To 3For intY = 1 To 5.Ce

12、ll(intX, intY). Cell: R & intX & , C & intYNext intYNext intXEnd WithEnd Sub013将Blue变量的值设为 6,如果该变量不存在, 本示例将该变量添加至文档, 并将值设为6。For Each aVar InIf = Blue Then num =Next aVarIf num = 0 ThenName:=Blue”, Value:=6Else(num).Value = 6End If014在文档关闭以前提示用户保存文档。Sub PromptToSaveAndClose()Dim doc As DocumentFor Ea

13、ch doc In DocumentsSaveChanges:=wdPromptToSaveChangesNextEnd Sub015若要确定文档是否处于打开状态,可使用For Each.Next语句列举Documents集合中 的元素。如果文档 是打开的,则下列示例激活该文档, 如果没有打开文档, 则将该文档打 开。Sub ActivateOrOpenDocument()Dim doc As DocumentDim docFound As BooleanFor Each doc In DocumentsIf InStr(1, , , 1) ThendocFound = TrueExit Fo

14、rElsedocFound = FalseEnd IfNext docIf docFound = False Then FileName:=End Sub016第三个多级符号列表模板创建另一种编号样式。Set myTemp = ListGalleries(wdOutlineNumberGallery).ListTemplates(3)For i = 1 to 9If i Mod 2 = 0 Then(i).NumberStyle = _wdListNumberStyleUppercaseRomanElse(i).NumberStyle = _wdListNumberStyleLowercaseRomanEnd IfNext i017 将活动文档中每个多级符号列表的编号样式更改为大写字母。For Each lt InFor Each ll In=wdListNumberStyleUppercaseLetterNext llNext lt018将活动文档页脚中的页码格式设置为小写罗马数字。For Each sec In(wdHeaderFooterPrimary).PageNumbers _.NumberStyle = wdPageNumberStyleLowercaseRomanNext sec019显示活动文档各列表的项数。For Each li InMsgBox

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1