2016-05-16 71 views
0

我已經寫了一個for循環來檢查幻燈片中智能藝術中使用的每種字體大小,並輸出字體大小爲形狀中每個文本塊的大小。出於某種原因,數組中的第一個條目正確更新(例如,我將文本塊作爲與字體大小相連的字符串),但數組中的任何後續條目只會更新字體大小,但不要抓取實際塊的文字。該陣列正在被正確計數(例如5個智能藝術形狀被正確計數)。智能藝術陣列

Dim j,e,f as integer 
Dim osh as shape 
Dim osl as slide 

Dim smrtCount as integer 
Dim osmrtSize() 
dim osmrtSizeMatch() 

set osl = activewindow.view.slide 

For each 
With osh in osl.shapes 
If .Type = msoSmartArt Then 
      smrtCount = smrtCount + .GroupItems.Count 
      ReDim Preserve osmrtSizeMatch(1 To smrtCount) 
      ReDim Preserve osmrtSize(1 To smrtCount) 
      For j = 1 To .GroupItems.Count 
       e = e + 1 
       f = f + 1 
       osmrtSize(e) = .GroupItems(j).TextFrame.TextRange.Runs(j).Font.Size 'store the sizes 
       osmrtSizeMatch(f) = .GroupItems(j).TextFrame.TextRange.Runs(j).Text '& " = " & .GroupItems(j).TextFrame.TextRange.Runs(j).Font.Size '& vbCrLf 
      Next j 
End If 

回答

0

想通了。需要使用.smartart.allnodes(),而不是.groupitems:

osmrtSizeMatch(f) = .SmartArt.AllNodes(j).TextFrame2.TextRange.Text 
0

尋址時通過你需要做的項目的.HasTextFrame檢查,否則會出錯e.g時的SmartArt包括行項目組的SmartArt。