【发布时间】:2022-01-03 23:12:57
【问题描述】:
我有数百张用于单个样本的照片,需要裁剪然后插入到 PowerPoint 幻灯片中。在纵向模式下,每张幻灯片六张照片,所有照片的文本标签相同。 PowerPoint 相册最多只能导入 4 张照片。 我发现一些代码与自定义占位符布局相结合,该布局计算我为该特定示例选择的图像数量,然后为每张新幻灯片放置一张照片。但是,每张幻灯片我需要 6 张照片。以下代码不包含裁剪代码。
谁能帮忙?
代码贴在下面
Public Function GetLayout( _
LayoutName As String, _
Optional ParentPresentation As Presentation = Nothing) As CustomLayout
If ParentPresentation Is Nothing Then
Set ParentPresentation = ActivePresentation
End If
Dim oLayout As CustomLayout
For Each oLayout In ParentPresentation.SlideMaster.CustomLayouts
If oLayout.Name = LayoutName Then
Set GetLayout = oLayout
Exit For
End If
Next
End Function
Sub ImportABunch2()
Dim i As Long
Dim oSlide As Slide
Dim oPicture As Shape, oContentHolder As Shape
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(Type:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
.Show
End With
If dlgOpen.SelectedItems.Count = 0 Then Exit Sub
For i = 1 To dlgOpen.SelectedItems.Count
''Dim oSlides As Slides, oSlide As Slide
Set oSlides = ActivePresentation.slides
Set oSlide = oSlides.AddSlide(oSlides.Count + 1, GetLayout("Smiley"))
For Each oContentHolder In oSlide.Shapes
If oContentHolder.Type = msoPlaceholder And oContentHolder.PlaceholderFormat.ContainedType = msoAutoShape Then
Set oPicture = oSlide.Shapes.AddPicture(FileName:=dlgOpen.SelectedItems(i), _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=0, Top:=0, Width:=100, Height:=100)
GoTo NextSlide
End If
Next
NextSlide:
Next i
End Sub
【问题讨论】:
标签: vba image powerpoint crop placeholder