循环在WORD+VBA中的应用_第1页
循环在WORD+VBA中的应用_第2页
循环在WORD+VBA中的应用_第3页
循环在WORD+VBA中的应用_第4页
循环在WORD+VBA中的应用_第5页
已阅读5页,还剩67页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、时磊忖呎 循环在WORD VBA 中的应用 001在活动文档的开头插入一张4列3行的表格。For Each.Next结构用于循环遍历表格 中的每个单元格。在For Each.Next结构中,InsertAfter方法用于将文字添至表格单元格 (单元格1、单元格2、以此类推)。 Sub CreateNewTable() Dim docActive As Docume nt Dim tblNew As Table Dim celTable As Cell Dim in tCo unt As In teger Set docActive = ActiveDocume nt Set tblNew =

2、docActive.Tables.Add( _ Ran ge:=docActive.Ra nge(Start:=0, En d:=0), NumRows:=3, _ NumColum ns:=4) in tCou nt = 1 For Each celTable In tblNew.Ra nge.Cells celTable.Ra nge.l nsertAfter Cell & in tCou nt in tCou nt = in tCou nt + 1 Next celTable tblNew.AutoFormat Format:=wdTableFormatColorful2, _ Appl

3、yBorders:=True, Apply Fon t:=True, ApplyColor:=True End Sub 002在活动文档中第一张表格的第一个单元格中插入文字。Cell方法返回单独的Cell对 象。Range属性返回一个 Range对象。Delete方法用于删除现有的文字,而InsertAfter方 法用于插入文字“ Cell 1,1 ”。 Sub In sertText In Cell() If ActiveDocume nt.Tables.Co unt = 1 Then With ActiveDocument.Tables(1).Cell(Row:=1, Column:=1)

4、.Range .Delete n sertAfter Text:=Cell 1,1 End With End If End Sub 003返回并显示文档中第一张表格的第一行中每个单元格的内容。 Sub ReturnTableText() Dim tbl One As Table Dim celTable As Cell 时磊5说- Dim rn gTable As Range Set tbl One = ActiveDocume nt.Tables(l) For Each celTable In tblO ne.Rows(1).Cells Set rngTable = ActiveDocume

5、nt.Range(Start:=celTable.Range.Start, _ En d:=celTable.Ra nge.E nd - 1) MsgBox rngTable.Text Next celTable End Sub Sub ReturnCellText() Dim tbl One As Table Dim celTable As Cell Dim rn gTable As Range Set tbl One = ActiveDocume nt.Tables(1) For Each celTable In tblO ne.Rows(1).Cells Set rn gTable =

6、celTable.Ra nge rn gTable.MoveE nd Un it:=wdCharacter, Coun t:=-1 MsgBox rngTable.Text Next celTable End Sub 004在活动文档的开头插入用制表符分隔的文本,然后将这些文本转换为表格。 Sub Con vertExisti ngText() With Docume nts.Add.Co ntent .InsertBefore one & vbTab & two & vbTab & three & vbCr .Con vertToTable Separator:=Chr(9), NumRow

7、s:=1, NumColu mn s:=3 End With End Sub 005定义一个数组,该数组的元素个数等于文档中第一张表格(假定为Optio n Base 1 )中 的单元格数。For Each.Next结构用于返回每个表格单元格的内容,并将文字指定给相应的 数组元素。 Sub ReturnCellCo nte ntsToArray() Dim in tCells As In teger Dim celTable As Cell Dim strCells() As Stri ng Dim in tCo unt As In teger Dim rn gText As Range If

8、 ActiveDocume nt.Tables.Co unt = 1 Then With ActiveDocume nt.Tables(1).Ra nge in tCells = .Cells.Cou nt ReDim strCells(i ntCells) in tCou nt = 1 时需Sr彳 For Each celTable In .Cells Set rn gText = celTable.Ra nge rn gText.MoveE nd Un it:=wdCharacter, Coun t:=-1 strCells(i ntCo unt) = rn gText in tCou n

9、t = in tCou nt + 1 Next celTable End With End If End Sub 006将当前文档中的表格复制到新文档中。 Sub CopyTablesToNewDoc() Dim docOld As Docume nt Dim rn gDoc As Range Dim tblDoc As Table If ActiveDocume nt.Tables.Co unt = 1 Then Set docOld = ActiveDocume nt Set rngDoc = Docume nts.Add.Ra nge(Start:=0, En d:=0) For Eac

10、h tblDoc In docOld.Tables tblDoc.Ra nge.Copy With rngDoc P aste .Collapse Direction:=wdCollapseE nd n sertParagraphAfter .Collapse Direction:=wdCollapseE nd End With Next End If End Sub 007显示Documents集合中每个文档的名称。 Sub LoopThroughOpe nDocume nts() Dim docOpe n As Docume nt For Each docOpe n In Docume n

11、ts MsgBox docOpe n. Name Next docOpe n End Sub 008使用数组存储活动文档中包含的所有书签的名称。 Sub LoopThroughBookmarks() Dim bkMark As Bookmark 时需Sr彳 Dim strMarks() As Stri ng Dim in tCo unt As In teger If ActiveDocume nt.Bookmarks.Cou nt 0 The n ReDim strMarks(ActiveDocume nt.Bookmarks.Cou nt - 1) in tCou nt = 0 For Ea

12、ch bkMark In ActiveDocume nt.Bookmarks strMarks( in tCo unt) = bkMark.Name in tCou nt = in tCou nt + 1 Next bkMark End If End Sub 009更新活动文档中的DATE域。 Sub UpdateDateFields() Dim fldDate As Field For Each fldDate In ActiveDocume nt.Fields If InStr(1, fldDate.Code, Date, 1) Then fldDate.Update Next fldDa

13、te End Sub 010如果名为File name”的词条是 AutoTextE ntries集合中的一部分,则以下示例显示一 条消息。 Sub Fin dAutoTextE ntry() Dim atxtE ntry As AutoTextE ntry For Each atxtE ntry In ActiveDocume nt.AttachedTemplate.AutoTextE ntries If atxtE ntry.Name = File name The n _ MsgBox The File name AutoText entry exists. Next atxtE ntr

14、y End Sub 011在第一个表格中添加一行,然后将文本Cell插入该行。 Sub Cou ntCells() Dim tblNew As Table Dim rowNew As Row Dim celTable As Cell Dim in tCo unt As In teger in tCou nt = 1 Set tblNew = ActiveDocume nt.Tables(1) Set rowNew = tblNew.Rows.Add(BeforeRow:=tblNew.Rows(1) For Each celTable In rowNew.Cells celTable.Ra n

15、ge.l nsertAfter Text:=Cell & in tCou nt 时需Sr彳 in tCou nt = in tCou nt + 1 Next celTable End Sub 012向新文档中添加一个3行5列的表格,然后在表格的每个单元格中插入数据。 Sub NewTable() Dim docNew As Docume nt Dim tblNew As Table Dim intX As In teger Dim intY As In teger Set docNew = Docume nts.Add Set tblNew = docNew.Tables.Add(Select

16、io n.Ra nge, 3, 5) With tblNew For intX = 1 To 3 For intY = 1 To 5 .Cell(i ntX, i ntY).Ra nge.l nsertAfter Cell: R & intX & , C & intY Next intY Next intX .Colu mn s.AutoFit End With End Sub 013将Blue变量的值设为 6,如果该变量不存在,本示例将该变量添加至文档,并将值 设为6。 For Each aVar In ActiveDocume nt.Variables If aVar.Name = Blu

17、e Then num = aVarn dex Next aVar If num = 0 The n ActiveDocume nt.Variables.Add Name:=Blue, Value:=6 Else ActiveDocume nt.Variables( nu m).Value = 6 End If 014在文档关闭以前提示用户保存文档。 Sub PromptToSaveA ndClose() Dim doc As Docume nt For Each doc In Docume nts doc.Close SaveCha nges:=wdPromptToSaveCha nges N

18、ext End Sub 时磊忖呎 015若要确定文档是否处于打开状态,可使用For Each.Next语句列举 Documents集合中 的元素。如果文档Sample.doc是打开的,则下列示例激活该文档,如果没有打开文档,则 将该文档打开。 Sub ActivateOrOpe nDocume nt() Dim doc As Docume nt Dim docF ound As Boolea n For Each doc In Docume nts If In Str(1, doc.Name, sample.doc, 1) The n doc.Activate docF ound = True

19、 Exit For Else docF ound = False End If Next doc If docF ound = False Then Docume nts.Ope n FileNamehSample.doc End Sub 016第三个多级符号列表模板创建另一种编号样式。 Set myTemp = ListGalleries(wdOutli neNumberGallery). ListTemplates(3) For i = 1 to 9 If i Mod 2 = 0 The n myTemp. ListLevels(i).NumberStyle = _ wdListNumbe

20、rStyleUppercaseRoma n Else myTemp. ListLevels(i).NumberStyle = _ wdListNumberStyleLowercaseRoma n End If Next i 017将活动文档中每个多级符号列表的编号样式更改为大写字母。 For Each lt In ActiveDocume nt.ListTemplates For Each ll In lt.listlevels ll.NumberStyle = wdListNumberStyleUppercaseLetter Next ll Next lt 018将活动文档页脚中的页码格式设

21、置为小写罗马数字。 For Each sec In ActiveDocume nt.Sect ions sec.Footers(wdHeaderFooterPrimary).PageNumbers _ 时磊忖呎 .NumberStyle = wdPageNumberStyleLowercaseRoma n Next sec 019显示活动文档各列表的项数。 For Each li In ActiveDocume nt.Lists MsgBox li.Cou ntNumberedltems Next li 020显示活动文档中每个段落的样式。 For Each para in ActiveDoc

22、ume nt.Paragraphs MsgBox para.Style Next para 021交替设置活动文档中的所有段落为“标题 3”和“正文”样式。 For i = 1 To ActiveDocume nt. Paragraphs.Co unt If i Mod 2 = 0 The n ActiveDocume nt.Paragraphs(i).Style = wdStyleNormal Else: ActiveDocume nt.Paragraphs(i).Style = wdStyleHeadi ng3 End If Next i 022显示所选内容中每个字符的样式。Charact

23、ers集合的每个元素都是一个Range对象。 For each c in Select ion. Characters MsgBox c.Style Next c 023将从Normal模板中删除名为“ Custom 1 ”的工具栏。 Dim cbLoop As Comma ndBar For Each cbLoop In Comma ndBars If cbLoop.Name = Custom 1 The n Applicati on.Organi zerDelete Source:=NormalTemplate.Name, _ Name:=Custom 1, _ Object:=wdOrg

24、a nizerObjectComma ndBars End If Next cbLoop 时需Sr彳 024提示用户删除活动文档的相关模板中的每一个“自动图文集”词条。如果用户单击“确 定”按钮,则将删除“自动图文集”词条。 Dim atE ntry As AutoTextE ntry Dim in tResp onse As In teger For Each atE ntry In _ ActiveDocume nt.AttachedTemplate.AutoTextE ntries in tResp onse = _ MsgBox(Do you want to delete the &

25、atE ntry.Name _ & AutoText en try?, vbYesNoCa ncel) If in tResp onse = vbYes Then With ActiveDocume nt.AttachedTemplate Applicati on.Organi zerDelete _ Source:= .Path & & .Name, _ Name:=atE ntry.Name, _ Object:=wdOrga nizerObjectAutoText End With ElseIf in tResp onse = vbCa ncel The n Exit For End I

26、f Next atE ntry 025显示Word启动时自动加载的每一加载项的名称。 Dim addi nLoop as AddI n Dim blnFound as Boolea n blnFound = False For Each addi nLoop In AddI ns With addi nLoop If .Autoload = True The n MsgBox .Name blnFound = True End If End With Next addi nLoop If blnFound True The n _ MsgBox No add-i ns were loaded

27、automatically. 026判断名为“ Gallery.dot ”的加载项是否自动加载。 Dim addi nLoop as AddI n For Each addi nLoop In AddI ns If InStr(LCase$(addinLoop.Name), gallery.dot) 0 Then If addi nLoop.Autoload = True The n Msgbox Autoload 时需忖呎 End If Next addi nLoop 027为所选内容的第一节的每个页面添加由黑点构成的边框。 Dim borderLoop As Border For Each

28、 borderLoop In Selecti on .Secti on s(1).Borders With borderLoop .ArtStyle = wdArtBasicBlackDots .ArtWidth = 6 End With Next borderLoop 028为活动文档中的第一节的每个页面添加由特定图片所构成的边框。 Dim borderLoop As Border With ActiveDocume nt.Sectio ns(1) .Borders.Always InFront = True For Each borderLoop In .Borders With bord

29、erLoop .ArtStyle = wdArtPeople .ArtWidth = 15 End With Next borderLoop End With 029如果未将 Word设置为自动更新链接,则更新活动文档中所有以OLE对象形式链接 的图形。 Dim shapeLoop as Shape For Each shapeLoop In ActiveDocume nt.Shapes With shapeLoop If .Type = msoL in kedOLEObject The n If .L in kFormat.AutoUpdate = False Then .Lin kForm

30、at.Update End If End If 030更新活动文档中未被自动更新的域。 Dim fieldLoop as Field For Each fieldLoop In ActiveDocume nt.Fields End With Next s 时磊5说- If fieldLoop. Li nkFormat.AutoUpdate = False The n _ fieldLoop.L in kFormat.Update Next fieldLoop 031在活动文档中的所有居中段落底部应用下边框。 For Each para In ActiveDocume nt.Paragraphs

31、 If para.Alig nment = wdAlig nParagraphCe nter The n para.Borders(wdBorderBottom).L in eStyle = wdLi neStyleSi ngle para.Borders(wdBorderBottom).L in eWidth = wdL in eWidth300pt End If Next para 032为当前节中的所有页面添加边框。 For Each aBorder In Select ion. Sect ion s(1).Borders aBorder.ArtStyle = wdArtBasicBla

32、ckDots aBorder.ArtWidth = 6 Next aBorder 033检查活动文档中的所有样式,如果检查到一个非内置样式,则显示该样式的名称。 Dim styleLoop As Style For Each styleLoop in ActiveDocume nt.Styles If styleLoop.BuiltIn = False Then Msgbox styleLoop.NameLocal End If Next styleLoop 034检查应用程序中创建的所有题注标签,如果检查到一个非内置的题注标签,则显示该 标签的名称。 Dim clLoop As Capti

33、on Label For Each clLoop in Capti on Labels If clLoop.BuiltIn = False The n Msgbox clLoop.Name End If Next clLoop 035在父节点中添加子节点,并在父节点中显示文本以代表创建的子节点数目。 Sub Cou ntChildNodes() Dim shpDiagram As Shape Dim dgnN ode As DiagramNode 时需Sr彳 Dim shpText As Shape Dim in tCo unt As In teger Add radial diagram t

34、o the curre nt docume nt Set shpDiagram = ThisDocume nt.Shapes.AddDiagram _ (Type:=msoDiagramRadial, Left:=10, _ Top:=15, Width:=400, Height:=475) Add first node to the diagram Set dgnN ode = shpDiagram.DiagramNode.Childre n.AddNode Add three child no des For in tCou nt = 1 To 3 dgnN ode.Childre n.A

35、ddNode Next in tCou nt Add a text box for each node in the diagram For in tCou nt = 1 To 4 Set shpText = shpDiagram.DiagramNode.Childre n(1).TextShape shpText.TextFrame.TextRa nge.Text = Str(i ntCo unt) Next in tCou nt End Sub 036将与活动文档相关的模板中的所有“自动图文集”词条复制到Normal模板中。 Dim atE ntry As AutoTextE ntry F

36、or Each atE ntry In _ ActiveDocume nt.AttachedTemplate.AutoTextE ntries Applicati on.Organi zerCopy _ Source:=ActiveDocume nt.AttachedTemplate.FullName, _ Desti natio n:=NormalTemplate.FullName, Name:=atE ntry.Name, _ Object:=wdOrga nizerObjectAutoText Next atE ntry 037如果活动文档中含有名为“SubText”的样式,本示例将该样

37、式复制到 C:TemplatesTemplate1.dot 中。 Dim styleLoop As Style For Each styleLoop In ActiveDocume nt.Styles If styleLoop = SubText The n Applicatio n.Organi zerCopy Source:=ActiveDocume nt.Name, _ Desti natio n:=C:TemplatesTemplate1.dot, _ Name:=SubText, _ Object:=wdOrga nizerObjectStyles End If Next style

38、Loop 时磊5说- 038显示各打开文档的名称。 For Each aDoc In Docume nts aName = aName & aDoc.Name & vbCr Next aDoc MsgBox aName 039查看Documents集合以判定名为Report.doc”的文档是否已打开。如果该文档包含 在Documents集合中,则激活该文档;否则,打开该文档。 For Each doc In Docume nts If doc.Name = Report.doc Then found = True Next doc If found True The n Docume nts.

39、Ope n FileName:=C:Docume ntsReport.doc Else Docume nts(Report.doc).Activate End If 040如果FirstLetterExceptions集合包含缩写addr.,则下列示例将其从中删除。 For Each aExcept In AutoCorrect.FirstLetterExceptions If aExcept.Name = addr. Then aExcept.Delete Next aExcept 041创建一篇新文档,然后插入所有的自动更正的首字母例外项。 Docume nts.Add For Each

40、aExcept In AutoCorrect.FirstLetterExceptions With Selectio n n sertAfter aExcept.Name n sertParagraphAfter .Collapse Direction:=wdCollapseE nd End With Next aExcept 042显示与Windows集合的第一个窗口相关的窗格中所有的非打印字符。 For Each myPa ne In Win dows(1).Pa nes myPa ne.View.ShowAII = True Next myPa ne 时需Sr彳 043设置 Window

41、s集合中所有窗口的视图选项。 For Each myWindow In Win dows With myWin dow.View .ShowTabs = True .ShowParagraphs = True .Type = wdNormalView End With Next myWi ndow 044将包含所选内容的节的格式设置为三栏。For Each.Next循环用于显示 TextColumns 集合中每一列的宽度。 Selectio n.PageSetup.TextColu mn s.SetCo unt NumColu mn s:=3 For Each acol In Selecti

42、on .PageSetup.TextColu mns MsgBox Width= & Poi ntsTol nches(acol.Width) Next acol 045显示活动文档中每一个域的域代码。 Dim fieldLoop As Field For Each fieldLoop In ActiveDocume nt.Fields MsgBox Chr(34) & fieldLoop.Code.Text & Chr(34) Next fieldLoop 046判断活动文档中是否包含一个名为“Title ”的邮件合并域。 Dim fieldLoop As Field For Each fi

43、eldLoop In ActiveDocume nt.MailMerge.Fields If In Str(1, fieldLoop.Code.Text, Title, 1) The n MsgBox A Title merge field is in this docume nt End If Next fieldLoop 047如果名为“ acheive”的“自动更正”词条是AutoCorrectEntries集合的一员,则下列示 例将该词条删除。 Sub DeleteAutoTextE ntry() Dim aceE ntry As AutoCorrectE ntry For Each

44、aceE ntry In AutoCorrect.E ntries If aceE ntry.Name = acheive The n aceE ntry.Delete Next aceE ntry End Sub 时磊5说- 048为活动文档的所有超链接创建快捷方式,并将其添加到“收藏夹”文件夹。 For Each myHyperl ink In ActiveDocume nt.Hyperl inks myHyperli nk.AddToFavorites Next myHyperl ink 049为Sales.doc创建快捷方式,并将其添加至“收藏夹”文件夹。如果 Sales.doc还未打

45、 开,本示例将从 C:Documents文件夹打开该文档。 For Each doc in Docume nts If LCase(doc.Name) = sales.doc Then isOpe n = True Next doc If isOpe n True The n Docume nts.Ope n _ FileName:=C:Docume ntsSales.doc Docume nts(Sales.doc).AddToFavorites 050为活动文档中第一节的每个页面添加单线型边框,然后设置每个边框到页面边缘的距 离。 Dim borderLoop As Border With

46、 ActiveDocume nt.Sectio ns(1) For Each borderLoop In .Borders borderLoop.L in eStyle = wdL in eStyleS in gle borderLoop.Li neWidth = wdL in eWidth050pt Next borderLoop With .Borders .Dista nceFrom = wdBorderDista nceFromPageEdge .Dista nceF romTop = 20 .Dista nceFromLeft = 22 .Dista nceF romBottom =

47、 20 .Dista nceFromRight = 22 End With End With 051为所选内容的第一节的每个页面添加边框,然后将文本与页面边框的距离设置为6 磅。 Dim borderLoop As Border With Selectio n.Sectio ns(1) For Each borderLoop In .Borders borderLoop.ArtStyle = wdArtSeattle borderLoop.ArtWidth = 22 Next borderLoop With .Borders 时磊忖呎 .Dista nceFrom = wdBorderDist

48、a nceFromText .Dista nceF romTop = 6 .Dista nceF romLeft = 6 .Dista nceFromBottom = 6 .Dista nceF romRight = 6 End With End With 052如果文档在上次保存后进行了修改,本示例将保存该文档。 Dim docLoop As Docume nt For Each docLoop In Docume nts If docLoop.Saved = False Then docLoop.Save Next docLoop 053先将文档的左右边距设置为0.5英寸,然后打印所有打开

49、的文档。 Dim docLoop As Docume nt For Each docLoop In Docume nts With docLoop .PageSetup. LeftMargin = In chesToPoi nts(0.5) .PageSetup.RightMargin = In chesToPoi nts(0.5) .Pri ntOut End With Next docLoop 054删除活动文档正文和页脚中的所有域。 For Each aField in ActiveDocume nt.Fields aField.Delete Next aField Set myRa n

50、ge = ActiveDocume nt.Sectio ns(1).Footers _ (wdHeaderFooterPrimary).Ra nge For Each aField In myRa nge.Fields aField.Delete Next aField 055将底纹应用于选定内容中每张表格的首行。For Each.Next循环用于在选定内容的每张 表格中循环。 Sub ShadeAllFirstRows In Tables() Dim tblTable As Table If Selection.Tables.Count = 1 Then For Each tblTable

51、In Select ion. Tables tblTable.Rows(1).Shadi ng.Texture = wdTexture30Perce nt Next tblTable End If End Sub 056在安装的转换器中循环,如果发现WordPerfect 6.0转换器,本示例会使用该转换器保 存活动文档。 Sub SaveWithCo nverter() Dim cnvWrdPrf As FileCo nverter Look for WordPerfect file con verter And save docume nt using the con verter For

52、 the FileFormat con verter value For Each cn vWrdPrf In Applicati on. FileC on verters If cn vWrdPrf.ClassName = WrdPrfctWi n The n ActiveDocume nt.SaveAs FileName:=MyWP.doc, _ FileFormat:=c nvWrdPrf.SaveFormat End If Next cnvWrdPrf End Sub 057显示使用密码保存文档的过程。 Sub SaveWithPassword(docCurre nt As Docum

53、e nt, strPWD As Stri ng) With docCurre nt .SaveAs WritePassword:=strPWD End With End Sub 058当SpellingSuggestions方法应用于 Application 对象时,必须指定要检查的单词。 当GetSpellingSuggestions 方法应用于一个区域时,则检查该区域的第一个单词。下例检 查活动文档中的任意单词是否存在拼写建议。如果有,则在消息框中显示这些建议。不能 在拼写建议集合中添加或删除建议。拼写建议是从主词典或自定义词典中获取的。 For Each wd In ActiveDocu

54、me nt.Words Set sugg = wd.GetSpelli ngSuggesti ons If sugg.Co unt 0 Then For Each ss In sugg MsgBox ss.Name Next ss End If Next wd 时需Sr彳 059在活动文档所有文字部分中删除与主文本部分不同的自定义字符格式。 For Each aStory In ActiveDocume nt.StoryRa nges If aStory.StoryType wdMai nTextStory The n aStory.Fo nt.Reset Next aStory 060在活动

55、文档的各部分中寻找“Microsoft Word ”,如找到则将其设置为斜体格式。 For Each myStoryRa nge In ActiveDocume nt.StoryRa nges myStoryRa nge.Fi nd.Execute _ Fi ndText:=Microsoft Word, Forward:=True While myStoryRa nge. Fin d.F ound myStoryRa nge.l talic = True myStoryRa nge.Fi nd.Execute _ Fi ndText:=Microsoft Word, Forward:=Tru

56、e Wend While Not (myStoryRa nge.NextStoryRa nge Is Nothi ng) Set myStoryRa nge = myStoryRa nge.NextStoryRa nge myStoryRa nge.Fi nd.Execute _ Fi ndText:=Microsoft Word, Forward:=True While myStoryRa nge. Fin d.F ound myStoryRa nge.l talic = True myStoryRa nge.Fi nd.Execute _ Fi ndText:=Microsoft Word

57、, Forward:=True Wend Wend Next myStoryRa nge 061包含内置“ Normal ”样式的样式分隔符的所有段落设置格式。 Sub StyleSep() Dim pghDoc As Paragraph For Each pghDoc In ThisDocume nt. Paragraphs If pghDocsStyleSeparator = True Then pghDoc.Ra nge.Select Selectio n.Style = Normal End If Next pghDoc End Sub 062在每个样式分隔符后添加一个段落,然后删除样

58、式分隔符。 Sub RemoveStyleSeparator() Dim pghDoc As Paragraph 时磊5说- Dim styName As Stri ng Loop through all paragraphs in docume nt to check if it is a style separator. If it is, delete it and enter a regular paragraph For Each pghDoc In ThisDocume nt. Paragraphs If pghDocsStyleSeparator = True Then pghD

59、oc.Ra nge.Select With Selecti on .Collapse (wdCollapseE nd) .TypeParagraph .MoveLeft (1) .TypeBackspace End With End If Next pghDoc End Sub 063在所选段落中2.5英寸处添加一个制表位,并显示TabStops集合中每一项目的位置。 Selectio n.Paragraphs.TabStops.Add Positi on :=l nchesToPoi nts(2.5) For Each aTab In Selecti on .Paragraphs.TabSt

60、ops MsgBox Position = _ & PointsTolnches(aTab.Position) & inches Next aTab 064使用Paragraphs集合(或包含多个段落的一个范围)时,如果集合中各段制表位位置 不一致,就必须在各段中分别修改。下例删除活动文档中位于各段1英寸处的制表位。 For Each para In ActiveDocume nt.C onten t.Paragraphs para.TabStops(I nchesToPoi nts(1).CIear Next para 065显示活动文档附加的模板中为FileOpen命令指定的所有组合键。

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论