我对 VBA 很陌生,我有一个 ppt 演示文稿,我需要从幻灯片中获取所有形状。我需要获取其链接到的幻灯片的位置(左侧、顶部)和尺寸(宽度、高度)。关于我应该首先检查哪里的任何帮助?
我得到了一些东西,但仍需要改进。真的不知道它是否运作良好。
Sub Slide()
Dim sld As Slide
Dim shp As Shape
Dim count As Integer
count = 1
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
Debug.Print count
Debug.Print shp.Left
Debug.Print shp.Top
count = count + 1
Next shp
Next sld
Run Code Online (Sandbox Code Playgroud)
结束子
嵌套循环,循环活动演示文稿中的所有幻灯片以及每张幻灯片中的所有形状,输出您提到的信息以及每个形状的 ID 和名称。如果存在内部超链接,则输出有关链接幻灯片的一些信息。我还添加了代码来获取对链接幻灯片对象的引用。
Option Explicit
Sub OutputSlides()
Dim oSlide As Slide
Dim oShape As Shape
Dim i As Long
Dim oAction As ActionSetting
Dim oHyperlink As Hyperlink
For Each oSlide In ActivePresentation.Slides
For Each oShape In oSlide.Shapes
Debug.Print "Shape #" & oShape.Id & " (" & oShape.Name & ") - Slide: " & oSlide.SlideNumber & " Position: " & oShape.Left & "," & oShape.Top _
; " Size: " & oShape.Width & "x" & oShape.Height
For Each oAction In oShape.ActionSettings
On Error Resume Next
If oAction.Action = ppActionHyperlink Then
Set oHyperlink = oAction.Hyperlink
''See more: http://www.pptfaq.com/FAQ00162_Hyperlink_-SubAddress_-_How_to_interpret_it.htm
Dim parts() As String
Dim slideId As Long
Dim slideIndex As Long
Dim slideTitle As String
Dim linkedSlide As Slide
parts = Split(oHyperlink.SubAddress, ",")
slideId = CLng(parts(0))
slideIndex = CLng(parts(1))
slideTitle = parts(2)
If slideId > 0 Then
Debug.Print " --Internal hyperlink to slide #: " & slideIndex & "(id: " & slideId&; ", title: " & slideTitle & ")"
''this gets you a reference to the linked slide if you need it:
''Set linkedSlide = oShape.Parent.Parent.Slides(slideIndex)
End If
End If
Next oAction
Next oShape
Next oSlide
End Sub
Run Code Online (Sandbox Code Playgroud)
输出示例:
Shape #2 (Title 1) - Slide: 1 Position: 120,88,37504 Size: 720x188
Shape #3 (Subtitle 2) - Slide: 1 Position: 120,283,625 Size: 720x130,375
Shape #4 (CommandButton1) - Slide: 1 Position: 120,73 Size: 237x141
Shape #5 (TextBox1) - Slide: 1 Position: 514,1251,134,875 Size: 72x72
Shape #2 (Title 1) - Slide: 2 Position: 120,88,37504 Size: 720x188
Shape #3 (Subtitle 2) - Slide: 2 Position: 120,283,625 Size: 720x130,375
Shape #4 (CommandButton1) - Slide: 2 Position: 120,73 Size: 237x141
Shape #5 (TextBox1) - Slide: 2 Position: 514,1251,134,875 Size: 72x72
Shape #2 (Title 1) - Slide: 3 Position: 66,28,75 Size: 828x104,375
Shape #3 (Content Placeholder 2) - Slide: 3 Position: 66,143,75 Size: 828x342,625
Shape #5 (Straight Arrow Connector 4) - Slide: 3 Position: 175,4366,201,8028 Size: 263,662x140,9577
--Internal hyperlink to slide #: 3(id: 257, title: Slide 3)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9147 次 |
| 最近记录: |