簡體   English   中英

在不使用.type屬性的情況下計算PowerPoint中的形狀組

[英]Count the group of shapes in powerpoint without using .type property

我測試過的腳本是從excel應用程序運行的,它將計算圖片的形狀和實際形狀的數量(即文本框,占位符)。下面的腳本會彈出帶有圖片和形狀數量的消息

Sub countshapes()
Dim strname As String
Dim thisslide As Long
Dim strshape() As String

-----Count the number of slides in presentation 

For thisslide = 1 To ActivePresentation.Slides.count

With ActivePresentation.Slides(thisslide)
ReDim strshape(0 To 0)

For Each oshp In .Shapes

If InStr(1, oshp.Name, "Picture") > 0 Then
ReDim Preserve strshape(0 To a)
strshape(a) = oshp.Name
a = a + 1

Else

ReDim Preserve strshape(0 To d)
strshape(d) = oshp.Name
d = d + 1
End If

Next oshp
End With
Next
MsgBox a
MsgBox d

形狀和圖片的數量可以完美顯示,但是無法獲得形狀組的數量,這可以通過.type = msogroup屬性輕松實現,但是該屬性在某些具有許多分組形狀的演示文稿中無濟於事。

請像上面的腳本一樣,通過使用形狀名稱來幫助我更新腳本

您已經在問題中提到不想使用.Type屬性,而無需說明原因。 由於它為您提供了直接執行所需內容的方法,因此我將提及您可以測試每個oShp的.Type,如果是msoGroup,則oShp.GroupItems.Count將為您提供組中形狀的數量。 例如,您可以將每個形狀傳遞給此函數,然后將結果匯總:

Function CountGroupShapes(oSh As Shape) As Long
    If oSh.Type = msoGroup Then
        CountGroupShapes = oSh.GroupItems.Count
    Else
        CountGroupShapes = 1
    End If
End Function

請記住,如果在組中有組,這將無法給出准確的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM