whdream 2013-06-02 07:08 采纳率: 0%
浏览 2481

VBA 将一个WORD按文档文中某行 某列中编号 分为多个WORD

如何将以下代码 按固定区域字段另存为 且 根据 固定区域字段做文件名 把目录改为母文件目录
Sub BC()
'
' wenhui Macro
' 宏在 2013/6/1 由 Administrator 创建
'

 Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Dim oNewDoc As Word.Document
    Dim oRange As Word.Range
    Dim lCurrentStart As Long
    Dim lCurrentEnd As Long
    Dim lDocumentEnd As Long
    Dim lOutputCount As Long

    lOutputCount = 0

    Set oWord = GetObject(, "Word.Application")
    Set oDoc = ActiveDocument

    oDoc.Select
    lCurrentStart = oWord.Selection.Start
    lCurrentEnd = lCurrentStart
    lDocumentEnd = oWord.Selection.End

    oWord.Selection.Collapse wdCollapseStart

    Do While (lCurrentEnd < lDocumentEnd)
        oWord.Browser.Target = wdBrowsePage
        oWord.Browser.Next
        lCurrentEnd = oWord.Selection.End

        If (lCurrentStart = lCurrentEnd) Then
            lCurrentEnd = lDocumentEnd
        End If

        Set oRange = oDoc.Range(lCurrentStart, lCurrentEnd)

        Set oNewDoc = oWord.Documents.Add
        oRange.Copy
        oNewDoc.Range(0, 0).Paste

        lOutputCount = lOutputCount + 1
        oNewDoc.SaveAs FileName:="d:\" & lOutputCount & ".doc"
        oNewDoc.Close

        lCurrentStart = lCurrentEnd
    Loop

End Sub

  • 写回答

2条回答

  • 码界一棵葱 2016-08-19 02:53
    关注

    请问你的问题解决了么,我碰到和你一样的问题!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog