我有这段代码可以将图片导入Powerpoint。
Fucnction InsertPic (gfilename as string)
activeWindow.selection.sliderange.shapes.addpicture(_FileName:=gfilename,_
LinkToFile:=msoFalse,_
SaveWithDocument:=msoTrue, Right: 40, Top: 25,_
Width:=70, Height:=40).Select
我是否知道如何编辑此代码以将图片放入已经打开的PPT中,并且代码可以提示用户选择放入每张幻灯片中的图片(相同的,每张幻灯片中的一张图片)除了第一张和最后一张幻灯片,而不是我把文件的地址?
答案 0 :(得分:0)
要选择已打开的PPT,请使用以下代码:
Dim ppt As Object
Set ppt = GetObject(, "powerpoint.application")
提示用户选择使用某种图像
Dim sl As Object
dim gfilename as String
For Each sl In ppt.activepresentation.slides
FileName = Application.GetOpenFilename _
(FileFilter:="Pictures, *.jpg; *.gif", Title:="Select a Picture", MultiSelect:=False)
sl.Shapes.AddPicture FileName, 0, -1, 25, 40, 10, 40
Next sl
最后,为了省略第一张和最后一张幻灯片,添加条件
If sl.slidenumber > 1 And sl.slidenumber < ppt.activepresentation.slides.Count Then
结束:
Function InsertPic()
Dim ppt As Object
Dim sl As Object
Dim FileName As String
Set ppt = GetObject(, "powerpoint.application")
For Each sl In ppt.activepresentation.slides
If sl.slidenumber > 1 And sl.slidenumber < ppt.activepresentation.slides.Count Then
FileName = Application.GetOpenFilename _
(FileFilter:="Pictures, *.jpg; *.gif", Title:="Select a Picture", MultiSelect:=False)
sl.Shapes.AddPicture FileName, 0, -1, 25, 40, 10, 40
End If
Next sl
End Function