求助:VBA(word):for循环还没有结束就自动退出来了,并没有写break和exit for
大家好,
正在做个小程序:在文档中的每个标题前添加一个表格。
已经做好了FUNCTION来添加表格,运行无误,但是在主程序里的“for循环”总是在固定点无故跳出循环,也不报错。
大家请看图:
(不知道大家能不能开picasa。。。)
在最外层的for循环,数出来的段数是35段,但循环到第25段就结束了。。。
我的电邮:lhan.epf@gmail.com,我可以发给高手那个文档。
多谢多谢大家!
以下是我的源码:
Sub form()Dim doc1 As Word.DocumentSet doc1 = ActiveDocumentDim i_NumPara As LongDim NumPara As IntegerDim i As IntegerDim str_Input As Object'NumPara = doc1.Paragraphs.CountFor i_NumPara = 1 To doc1.Paragraphs.Count 'doc1.Paragraphs.Count Set str_Input = doc1.Paragraphs(i_NumPara) If str_Input.Style.NameLocal <> "正文" _ And str_Input.Style.NameLocal <> "超链接" _ And str_Input.Style.Type <> wdStyleTypeTable _ Then'On Error GoTo continue If str_Input.Style.ListLevelNumber <> 0 _ Or str_Input.Style.AutomaticallyUpdate = False _ Then doc1.Paragraphs(i_NumPara).Range.Select j = 2 For i = 1 To j doc1.Paragraphs(i_NumPara).Range.InsertParagraphBefore ActiveDocument.Paragraphs(i_NumPara).Range.Select Selection.Paragraphs.OutlineDemoteToBody '将所有选定段落降级为正文文本。 Next i My_Table i_NumPara = i_NumPara + 7 End If End If'continue:'NumPara = doc1.Paragraphs.Count + 1Next i_NumPara Selection.EndKey Unit:=wdStory Selection.Range.InsertParagraphAfter Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft Selection.Paragraphs.OutlineDemoteToBody My_Table End Sub