我对VBA不太熟,请教各位有没有办法在VB中将一个DOC分页保存呢

解决方案 »

  1.   

    我的方法,贴出来抛砖引玉吧。用VBA判断分页好像很麻烦,所以就每次取30行存为一个文件
    Dim wa As Object
    i = 1
    Set wa = CreateObject("word.application")
    wa.Visible = True
    wa.Documents.Open FileName:="c:\test.doc"
    taga:
    wa.Selection.MoveDown Unit:=wdLine, Count:=l + 1
    wa.Selection.HomeKey Unit:=wdLine ', Extend:=wdExtend
    wa.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
    If wa.Selection.Words.Count > 1 Then
      wa.Selection.Cut
      wa.ActiveDocument.SaveAs FileName:="C:\" & i & ".doc"
      i = i + 1
      wa.Selection.PasteAndFormat (wdPasteDefault)
      wa.Selection.HomeKey Unit:=wdStory
      wa.Selection.MoveDown Unit:=wdLine, Count:=l - 1, Extend:=wdExtend
      wa.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
      wa.Selection.Delete Unit:=wdCharacter, Count:=1
      wa.Selection.HomeKey Unit:=wdStory
      GoTo taga
    Else
      wa.ActiveDocument.SaveAs FileName:="C:\" & i & ".doc"
      j = i
    End If
    wa.Documents.Close
    这段程序运行不稳定,有时候正常,有时候就会报错
    听听各位对这个问题的想法