怎么快速取得word文档的结构?

hugebrush 2014-05-06 09:50:07
我目前用的办法是遍历文档的段落,根据各段落outlinelevel属性建立文档结构,但这种方法效率非常低,我处理一个1000多页的文档要几十分钟,而word打开同一个文档,3、4秒钟就能在导航窗格中显示出文档结构,很显然word有其他方式取得文档结构。怎么用VBA快速取得word文档结构?

用“GetCrossReferenceItems wdRefTypeHeading”有个问题:我处理的文档有些标题只设置大纲级别,没有应用标题样式,“GetCrossReferenceItems wdRefTypeHeading”返回的结果中缺少这些标题,但word导航窗格显示有这些标题。
...全文
775 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqzm0401 2014-08-01
  • 打赏
  • 举报
回复
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';>整合营销原是市场营销的一种有效营销方式,随着网络营销的发展,网络整合营销也逐渐兴起并被广泛应用到各企业中,整合营销要求将目前最有效的多种网络营销方式优势结合,能够让企业的网络营销效果更显著。那么如何进行<a target=_blank href=http://www.seo3800.com>网络整合营销</a>呢?笔者接下来就说说自己的一些经验之谈:</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=margin-left:39.0000pt;text-indent:-18.0000pt;>
<span style=font-size:10.5000pt;font-family:'Times;><span>1、<span> </span></span></span><span style=font-size:10.5000pt;font-family:'宋体';>制定详细的计划</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=margin-left:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';>整合营销要做多种营销方式,为了保证企业的网络整合营销能够有序进行,必须要制定详细的计划。这个计划并不是随意制定的,首先要了解网络市场行情,以及同行的一些营销情况,然后结合公司的实际情况,制定详细的计划,这个计划应该包括整个网络整合营销大概要持续多长时间,分几个阶段进行,每个阶段要运用哪几种营销方式,这样才能保证网络整合营销有序进行。</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=margin-left:39.0000pt;text-indent:-18.0000pt;>
<span style=font-size:10.5000pt;font-family:'Times;><span>2、<span> </span></span></span><span style=font-size:10.5000pt;font-family:'宋体';>多种营销方式的综合运用</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=margin-left:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';>网络整合营销要求企业在网络营销的过程中,将多种有效营销方式优势结合,来实现网络营销的显著效果。所以在企业进行网络整合营销的过程中,目前市面上比较有效的网络营销方式,像论坛营销、博客营销、分类信息营销和邮件营销都要运用起来,此外问答营销、事件营销等比较有效的营销方式也可以综合运用。这是个复杂的实现过程,必要的时候可以选择网络营销软件来辅助,像具备多种网络营销方式的<span></span><span>组合营销软件就很不错。</span></span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=margin-left:39.0000pt;text-indent:-18.0000pt;>
<span style=font-size:10.5000pt;font-family:'Times;><span>3、<span> </span></span></span><span style=font-size:10.5000pt;font-family:'宋体';>对计划严谨的执行</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=margin-left:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';>再完美的计划,如果没有严谨地执行,那么也只是空谈,尤其是实现网络整合营销这样一个复杂而且长期的过程。更要对每一个环节都把关,严格地执行。只有高度的执行力才能让企业的网络整合营销达到更加显著的效果。</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=margin-left:39.0000pt;text-indent:-18.0000pt;>
<span style=font-size:10.5000pt;font-family:'Times;><span>4、<span> </span></span></span><span style=font-size:10.5000pt;font-family:'宋体';>对效果的实时跟踪</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
<p class=p0 style=margin-left:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';> </span>
</p>
<p class=p0 style=text-indent:21.0000pt;>
<span style=font-size:10.5000pt;font-family:'宋体';>企业在进行网络整合营销的过程中,效果到底怎么样?达到好的效果的原因是什么?如果效果不理想,那么是哪个环节出现了纰漏呢,这些都是企业在做网络整合营销的过程中需要持续跟踪了解的,这样才能及时发现问题,总结经验,达到显著效果。</span><span style=font-size:10.5000pt;font-family:'宋体';></span>
</p>
dsd999 2014-05-07
  • 打赏
  • 举报
回复
Public Sub CreateOutline()
    Dim docOutline As Word.Document
    Dim docSource As Word.Document
    Dim rng As Word.Range

    Dim astrHeadings As Variant
    Dim strText As String
    Dim intLevel As Integer
    Dim intItem As Integer

    Set docSource = ActiveDocument
    Set docOutline = Documents.Add

    ' Content returns only the
    ' main body of the document, not
    ' the headers and footer.
    Set rng = docOutline.Content
    astrHeadings = _
     docSource.GetCrossReferenceItems(wdRefTypeHeading)

    For intItem = LBound(astrHeadings) To UBound(astrHeadings)
        ' Get the text and the level.
        strText = Trim$(astrHeadings(intItem))
        intLevel = GetLevel(CStr(astrHeadings(intItem)))

        ' Add the text to the document.
        rng.InsertAfter strText & vbNewLine

        ' Set the style of the selected range and
        ' then collapse the range for the next entry.
        rng.Style = "Heading " & intLevel
        rng.Collapse wdCollapseEnd
    Next intItem
End Sub

Private Function GetLevel(strItem As String) As Integer
    ' Return the heading level of a header from the
    ' array returned by Word.

    ' The number of leading spaces indicates the
    ' outline level (2 spaces per level: H1 has
    ' 0 spaces, H2 has 2 spaces, H3 has 4 spaces.

    Dim strTemp As String
    Dim strOriginal As String
    Dim intDiff As Integer

    ' Get rid of all trailing spaces.
    strOriginal = RTrim$(strItem)

    ' Trim leading spaces, and then compare with
    ' the original.
    strTemp = LTrim$(strOriginal)

    ' Subtract to find the number of
    ' leading spaces in the original string.
    intDiff = Len(strOriginal) - Len(strTemp)
    GetLevel = (intDiff / 2) + 1
End Function

hugebrush 2014-05-07
  • 打赏
  • 举报
回复
谢谢回复。用“GetCrossReferenceItems wdRefTypeHeading”有个问题:我处理的文档有些标题只设置大纲级别,没有应用标题样式,“GetCrossReferenceItems wdRefTypeHeading”返回的结果中缺少这些标题,但word导航窗格显示有这些标题。
引用 1 楼 dsd999 的回复:
Public Sub CreateOutline()
    Dim docOutline As Word.Document
    Dim docSource As Word.Document
    Dim rng As Word.Range

    Dim astrHeadings As Variant
    Dim strText As String
    Dim intLevel As Integer
    Dim intItem As Integer

    Set docSource = ActiveDocument
    Set docOutline = Documents.Add

    ' Content returns only the
    ' main body of the document, not
    ' the headers and footer.
    Set rng = docOutline.Content
    astrHeadings = _
     docSource.GetCrossReferenceItems(wdRefTypeHeading)

    For intItem = LBound(astrHeadings) To UBound(astrHeadings)
        ' Get the text and the level.
        strText = Trim$(astrHeadings(intItem))
        intLevel = GetLevel(CStr(astrHeadings(intItem)))

        ' Add the text to the document.
        rng.InsertAfter strText & vbNewLine

        ' Set the style of the selected range and
        ' then collapse the range for the next entry.
        rng.Style = "Heading " & intLevel
        rng.Collapse wdCollapseEnd
    Next intItem
End Sub

Private Function GetLevel(strItem As String) As Integer
    ' Return the heading level of a header from the
    ' array returned by Word.

    ' The number of leading spaces indicates the
    ' outline level (2 spaces per level: H1 has
    ' 0 spaces, H2 has 2 spaces, H3 has 4 spaces.

    Dim strTemp As String
    Dim strOriginal As String
    Dim intDiff As Integer

    ' Get rid of all trailing spaces.
    strOriginal = RTrim$(strItem)

    ' Trim leading spaces, and then compare with
    ' the original.
    strTemp = LTrim$(strOriginal)

    ' Subtract to find the number of
    ' leading spaces in the original string.
    intDiff = Len(strOriginal) - Len(strTemp)
    GetLevel = (intDiff / 2) + 1
End Function

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧