使用文件夹中选定的图片填充每个形状并裁剪它们以填充 - VBA - Powerpoint 或 Word
我使用 PowerPoint 创建了几个由形状组组成的模板,我将复制这些模板以在 Word 文档中创建漂亮的图像库。
我的想法是自动化以下过程:
- 选择形状
- 形状格式>形状填充>图片>>从文件
- 图片格式>作物> 填充
通过宏进行
- :选择所选幻灯片中的所有形状
- 选择一个文件夹并选择图片
- 用图片填充每个形状
- 裁剪形状中的所有图片以填充形状
我有一个宏,可以在特定的位置上填充特定的形状借助文件对话框,可以使用图像进行滑动。感谢命令栏,我可以进行图片填充裁剪。
Sub FillPictureAndFillCrop()
Dim strFilePath As String
With Application.FileDialog(msoFileDialogFilePicker)
If .Show <> 0 Then
strFilePath = .SelectedItems(1)
With ActivePresentation.Slides(1).Shapes(1).Fill
.Visible = msoTrue
.UserPicture strFilePath
End With
ActivePresentation.Slides(1).Shapes(1).Select
CommandBars.ExecuteMso ("PictureFillCrop")
End If
End With
End Sub
我仍然需要将此宏扩展到所选幻灯片的所有形状以及我选择的每张图片。 我以前有一个宏,可以使用它选择多张图片并为每个新创建的幻灯片添加一张图片。 我想将其适应上面的宏。
Sub AddOneImagePerNewSlide()
Dim ImgI As Long, tmpDIAPO As Slide
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Add "Images", "*.png, *.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
For ImgI = 1 To .SelectedItems.Count
Set tmpDIAPO = ActivePresentation.Slides.Add(Index:=ImgI, Layout:=ppLayoutBlank)
tmpDIAPO.Shapes.AddPicture FileName:=.SelectedItems.Item(ImgI), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, Top:=0, _
Width:=-1, Height:=-1
Next
End If
End With
End Sub
我认为上面两个宏的混合会起作用。 可行吗?
With PowerPoint, I have created several templates made of groups of shapes that I would copy to create nice image galleries in a Word document.
My idea is to automate the following process:
- select a shape
- shape format > shape fill > picture > from a file
- picture format > crop > fill
by a macro that would do:
- select all shapes in the selected slide
- chose a folder and select pictures
- fill each shape with the pictures
- crop all the pictures in the shapes to fill the shapes
I have a macro that fill a specific shape on a specific slide with an image thanks to the filedialog. Thanks to commandbars I can do the PictureFillCrop.
Sub FillPictureAndFillCrop()
Dim strFilePath As String
With Application.FileDialog(msoFileDialogFilePicker)
If .Show <> 0 Then
strFilePath = .SelectedItems(1)
With ActivePresentation.Slides(1).Shapes(1).Fill
.Visible = msoTrue
.UserPicture strFilePath
End With
ActivePresentation.Slides(1).Shapes(1).Select
CommandBars.ExecuteMso ("PictureFillCrop")
End If
End With
End Sub
I still need to extend this macro to all the shapes of the selected slide with each pictures I have selected.
I have a previous macro with which I can select multiple pictures and add one picture per newly created slide.
I would like to adapt it to the macro above.
Sub AddOneImagePerNewSlide()
Dim ImgI As Long, tmpDIAPO As Slide
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Add "Images", "*.png, *.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
For ImgI = 1 To .SelectedItems.Count
Set tmpDIAPO = ActivePresentation.Slides.Add(Index:=ImgI, Layout:=ppLayoutBlank)
tmpDIAPO.Shapes.AddPicture FileName:=.SelectedItems.Item(ImgI), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, Top:=0, _
Width:=-1, Height:=-1
Next
End If
End With
End Sub
I think it would be a mix of the 2 above macro would work.
Is it doable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是可行的。
使用此宏,您将不需要选择形状。
Yes, it is doable.
With this macro you will not need to select the Shapes.
@Clemleb
要循环浏览每张幻灯片上的所有形状,您需要执行以下操作:
@Clemleb
To loop through all the shapes on each slide, you'd do something like this: