2009-10-15 2 views

답변

0

이 시도 :

foreach (Word.ContentControl contentcontrol in this.Application.ActiveDocument.ContentControls) 
{ 
    //Some action on all contentcontrol objects 
} 

을 그는 내가 같은 문제를 처리하고있어 문서의 StoryRanges

0

하지만,이 말씀을 운전에 (contentcontrols에 대한) 모든 범위에 반복하려고 작동하지 않는 경우 MATLAB에서. 워드 MVP로이 페이지는 나를 위해 문제를 해결 :

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

은 본질적으로, 당신은에 있습니다

  1. 루프 모든 Document.StoryRanges 통해 서로 이야기 형식의 첫 번째 범위를 얻을 수 있습니다.
  2. 각 범위 내에서 range.ContentControls에 대한 작업을 수행하십시오.
  3. range = range.NextStoryRange.
  4. 범위가 비게 될 때까지 2-4를 반복하십시오.
3

http://social.msdn.microsoft.com/Forums/is/vsto/thread/0eb0af6f-17db-4f98-bc66-155db691fd70

public static List<ContentControl> GetAllContentControls(Document wordDocument) 
    { 
     if (null == wordDocument) 
     throw new ArgumentNullException("wordDocument"); 

     List<ContentControl> ccList = new List<ContentControl>(); 

     // The code below search content controls in all 
     // word document stories see http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm 
     Range rangeStory; 
     foreach (Range range in wordDocument.StoryRanges) 
     { 
     rangeStory = range; 
     do 
     { 
      try 
      { 
      foreach (ContentControl cc in rangeStory .ContentControls) 
      { 
       ccList.Add(cc); 
      } 
      foreach (Shape shapeRange in rangeStory.ShapeRange) 
      { 
       foreach (ContentControl cc in shapeRange.TextFrame.TextRange.ContentControls) 
       { 
       ccList.Add(cc); 
       } 
      } 
      } 
      catch (COMException) { } 
      rangeStory = rangeStory.NextStoryRange; 

     } 
     while (rangeStory != null); 
     } 
     return ccList; 
    } 
에서 복사
관련 문제