首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VBA(word):for循环还没有结束就自动退出来了,并没有写break和exit for

2012-02-09 
求助:VBA(word):for循环还没有结束就自动退出来了,并没有写break和exit for大家好,正在做个小程序:在文档

求助:VBA(word):for循环还没有结束就自动退出来了,并没有写break和exit for
大家好,

正在做个小程序:在文档中的每个标题前添加一个表格。
已经做好了FUNCTION来添加表格,运行无误,但是在主程序里的“for循环”总是在固定点无故跳出循环,也不报错。
大家请看图:
(不知道大家能不能开picasa。。。)
   
  在最外层的for循环,数出来的段数是35段,但循环到第25段就结束了。。。
  我的电邮:lhan.epf@gmail.com,我可以发给高手那个文档。
多谢多谢大家!

以下是我的源码:

VB code
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



[解决办法]
设断点,在第25段的时候看看与别的有什么不同.
[解决办法]
检查一下段落标志。。。
[解决办法]
可疑处有两个:
1 把On Error GoTo continue注释掉之后没保存??
2 “i_NumPara = i_NumPara + 7” 干嘛用的?? 会不会破坏你的循环用意??

[解决办法]
如果有文件就好调试一点。

热点排行