|
这是从我的一个工具集里简化的代码,注释基本有了。
[code=vb]
'相同位置粘贴图片
Sub AddPics()
Dim k As Integer, i As Integer, sp As Shape, fd As FileDialog, s As String, r1 As Integer, r2 As Integer
Dim picX As Single, picY As Single
Const myTop = 140 '预计留下上面的3厘米左右位置,可自行修改
'打开文件对话框
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = True '允许多选
.Filters.Clear '清除文件类型过滤器
.Filters.Add "图片文件", "*.jpg;*.bmp;*.gif;*.png" '加入自定义过滤器
.Show '显示对话框
If .SelectedItems.Count = 0 Then Exit Sub '如果没选则退出程序
End With
k = ActiveWindow.Selection.SlideRange.SlideIndex '取得当前幻灯片序号
For i = 1 To fd.SelectedItems.Count '根据图片数量循环
If i = 1 Then
ActivePresentation.Slides(k).Select '选择当前幻灯片
Else
ActivePresentation.Slides.Add(Index:=k + 1, Layout:=ppLayoutText).Select '选择下一页新插入幻灯片
k = k + 1
End If
Set sp = ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:=fd.SelectedItems(i), LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=0, Top:=myTop) '插入图片
sp.LockAspectRatio = msoFalse '取消图片的纵横比锁定
sp.Width = ActivePresentation.PageSetup.SlideWidth '图片宽度等于页面宽度
sp.Height = ActivePresentation.PageSetup.SlideHeight - myTop '图片高度等于页面高度-设定值
Next
End Sub
[/code] |
|