2016-07-15 8 views
0

어떤 cutomvariables가 문서에서 사용되는지 알아 내려고하고 있지만 머리말이나 꼬리말에 정의되어있는 경우에 문제가 있는지 알아볼 때 문제가 있습니다. 여기 머리글과 페이지 모두에서 단어로 된 텍스트 찾기

모든 customVariables을 통해 루프 내 하위입니다 : 여기
Sub deleteCustomVarNotInUse() 
Dim doc As Document 
Set doc = ActiveDocument 
For i = 1 To Documents(doc).CustomDocumentProperties.Count 

     If CustomProperties.findProperty(doc, Documents(doc).CustomDocumentProperties(i).name) Then 

      'Delete variable... 
     End If 
Next i 
End Sub 

내가 here

Public Function findProperty(doc As Document, findText As String) As Boolean 
    On Error Resume Next 

    findProperty = False 
    Dim rng As Range 
    Dim intSecCount As Integer 
    Dim intHFType As Integer 

    Set rng = Documents(doc).Content 
    rng.Find.Execute findText:="DOCPROPERTY*" & findText, Forward:=True 
    If rng.Find.found = True Then 
     findProperty = True 
     Exit Function 
    End If 


    intSecCount = Documents(doc).Sections.Count 
    For intSection = 1 To intSecCount 
     With Documents(doc).Sections(intSection) 
      For intHFType = 1 To 3 
       Set rng = Documents(doc).Sections(intSection).Headers(intHFType).Range 
       rng.Find.Execute findText:="DOCPROPERTY*" & findText, Forward:=True 
       If rng.Find.found = True Then 
        findProperty = True 
        Exit Function 
       End If 
      Next intHFType 
     End With 
    Next intSection 



End Function 

답변

0

이에서 수정하려고하는 기능입니다 작동하는 것 같다 :

Public Function findProperty(doc As Document, findText As String) As Boolean 
    Dim rngStory As word.Range 
    Dim oFld As word.Field 


    findProperty = False 
    For Each rngStory In doc.StoryRanges 
     Do 
     For Each oFld In rngStory.Fields 
      If oFld.Type = wdFieldDocProperty Then 
       'Dig a little deeper and see what the field code contains. 
       If InStr(UCase(oFld.Code.Text), UCase(findText)) Then 
       findProperty = True 
       Exit Function 
       End If 
      End If 
     Next oFld 
     Set rngStory = rngStory.NextStoryRange 
     Loop Until rngStory Is Nothing 
    Next rngStory 

End Function 
관련 문제