设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1499|回复: 0
打印 上一主题 下一主题

更新文档中所有字段, 包括页眉与页脚中的字段

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2004-7-9 07:05:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
更新文档中所有字段, 包括页眉与页脚中的字段:

作者:Bryan Carbonnell   ,Nancy Hutson Hale

Public Sub UpdateAllFields()



'---------------------------------------------------------------------------------------

' Procedure: sUpdateFields (V2)

' DateTime : 20-Dec-2001

' Updated  : 06-Nov-2002 - Update fields in Text Boxes

' Author   : Bryan Carbonnell

'            With code by Nancy Hutson Hale

' Purpose  : To update all fields in the Word Document including TOC, TOA, TOF,

'             fields in text boxes and fields in headers/footers

'---------------------------------------------------------------------------------------



Dim doc As Document           ' Pointer to Active Document

Dim wnd As Window             ' Pointer to Document's Window

Dim lngMain As Long           ' Main Pane Type Holder

Dim lngSplit As Long          ' Split Type Holder

Dim lngActPane As Long        ' ActivePane Number

Dim rngStory As Range         ' Range Object for Looping through Stories

Dim TOC As TableOfContents    ' Table of Contents Object

Dim TOA As TableOfAuthorities ' Table of Authorities Object

Dim TOF As TableOfFigures     ' Table of Figures Object

Dim shp As Shape              ' Shape Object to get Textboxes



' Set Objects

Set doc = ActiveDocument

Set wnd = ActiveDocument.ActiveWindow



' get Active Pane Number

lngActPane = wnd.ActivePane.Index



' Hold View Type of Main pane

lngMain = wnd.Panes(1).View.Type



' Hold SplitSpecial

lngSplit = wnd.View.SplitSpecial



' Get Rid of any split

wnd.View.SplitSpecial = wdPaneNone



' Set View to Normal

wnd.View.Type = wdNormalView



' Loop through each story in doc to update

For Each rngStory In doc.StoryRanges

  If rngStory.StoryType = wdCommentsStory Then

    Application.DisplayAlerts = wdAlertsNone

    ' Update fields

    rngStory.Fields.Update

    Application.DisplayAlerts = wdAlertsAll

  Else

    ' Update fields

    rngStory.Fields.Update

  End If

Next



'Loop through text boxes and update

' added by Nancy Hutson Hale - Nov 6, 2002

For Each shp In doc.Shapes

  With shp.TextFrame

    If .HasText Then

      .TextRange.Fields.Update

    End If

  End With

Next



' Loop through TOC and update

For Each TOC In doc.TablesOfContents

  TOC.Update

Next



' Loop through TOA and update

For Each TOA In doc.TablesOfAuthorities

  TOA.Update

Next



' Loop through TOF and update

For Each TOF In doc.TablesOfFigures

  TOF.Update

Next



' Return Split to original state

wnd.View.SplitSpecial = lngSplit



' Return main pane to original state

wnd.Panes(1).View.Type = lngMain



' Active proper pane

wnd.Panes(lngActPane).Activate



' Close and release all pointers

Set wnd = Nothing

Set doc = Nothing



End Sub
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-29 21:27 , Processed in 0.089528 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表