2015-02-02 4 views
1

문서의 모든 필드를 업데이트하는 절차가 있습니다. 그러나 wdFieldDocVariable을 건너 뛰고 싶습니다. 항목 인덱스는 Type이어야합니다. 내가 생각Word 문서 필드 업데이트

Public Sub MyApplicationUpdate() 
hdWriteInfoLog ("BEGIN MACRO: MyApplicationUpdate") 
Dim oTOC As TableOfContents 
Dim oField As Field 

' Update Fields in all document StoryRanges 
Dim oStory As Range 
For Each oStory In ActiveDocument.StoryRanges 
    oStory.Fields.Update 
    If oStory.StoryType <> wdMainTextStory Then 
     While Not (oStory.NextStoryRange Is Nothing) 
      Set oStory = oStory.NextStoryRange 
      oStory.Fields.Update 
     Wend 
    End If 
Next oStory 
Set oStory = Nothing 

' Update all TablesOfContents 
For Each oTOC In ActiveDocument.TablesOfContents 
    oTOC.Update 
Next oTOC 

hdWriteInfoLog ("END MACRO:  MyApplicationUpdate") 
End Sub 
+0

'OStory'에서'wdFieldDocVariable'의 아이템 인덱스는 무엇입니까? –

+0

나는 그것이 "oStory.Type = wdFieldDocVariable이 아닌 경우"와 같은 것이어야한다고 생각합니다. " –

+0

'wdFieldDocVariable'이란 무엇입니까? 그것에 할당 된 것은 무엇입니까? –

답변

0

, 나는

'시험 절차를 ... 내가 거기에이 일을보다 효율적인 방법이지만, 적어도 작동 생각 공공 하위 MyApplicationUpdate을 답을 발견했다() hdWriteInfoLog는 ("MACRO를 BEGIN : MyApplicationUpdate") TableOfContents를 필드 희미한 oField2으로 희미한 oField으로 희미한 oTOC을 필드

' Update Fields in all document StoryRanges 
Dim oStory As Range 
For Each oStory In ActiveDocument.StoryRanges 
    For Each oField2 In oStory.Fields 
     If Not oField2.Type = wdFieldDocVariable Then 
      oField2.Update 
     End If 
    Next oField2 

    If oStory.StoryType <> wdMainTextStory Then 
     While Not (oStory.NextStoryRange Is Nothing) 
      Set oStory = oStory.NextStoryRange 
      ' oStory.Fields.Update 
      For Each oField2 In oStory.Fields 
       If Not oField2.Type = wdFieldDocVariable Then 
        oField2.Update 
       End If 
      Next oField2 
     Wend 
    End If 
Next oStory 
Set oStory = Nothing 

' Update all TablesOfContents 
For Each oTOC In ActiveDocument.TablesOfContents 
    oTOC.Update 
Next oTOC 

hdWriteInfoLog ("END MACRO:  MyApplicationUpdate") 

욕실로 d 서브