我对VBA很新,我有一个ppt演示文稿,我需要从幻灯片中获取所有形状。 我需要获得位置(左侧,顶部)和大小(宽度,高度)以及它所链接的幻灯片。 我应该先在哪里查看?
我得到了一些东西,但仍需要改进。不知道它是否运作良好。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { appRouting, appRoutingProviders } from './app.routing';
@NgModule({
imports: [
BrowserModule,
FormsModule,
appRouting,
],
declarations: [
RootComponent,
],
providers: [
appRoutingProviders
],
bootstrap: [AppComponent]
})
export class AppModule { }
End Sub
答案 0 :(得分:2)
嵌套循环,循环活动演示文稿中的所有幻灯片以及每张幻灯片中的所有形状,输出您提到的信息以及每个形状的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
示例输出:
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)