有没有办法以编程方式将图像添加到PowerPoint文件?
我需要对大约1000个PowerPoint文件执行此操作。
答案 0 :(得分:3)
您可能希望在此处使用FileSystemObject为特定目录中的每个文件运行Otaku代码
Dim objFSO As Object, objFile As Object, strPath As String, p as Presentation
strPath = "C:\Wherever\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
For Each objFile In objFSO.GetFolder(strPath).Files
If InStr(1, UCase(objFile.Name), ".JPG") + _
InStr(1, UCase(objFile.Name), ".GIF") + _
InStr(1, UCase(objFile.Name), ".PNG") + _
InStr(1, UCase(objFile.Name), ".BMP") > 0 Then
'# use Otaku's code above to add a presentation, the image, then close
Set p = Presentations.Add(msoFalse)
With p
.Slides.Add Index:=1, Layout:=ppLayoutBlank
.Slides(1).Shapes.AddPicture FileName:=strPath & objFile.Name, _
LinktoFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=10, Top:=10
.SaveAs strPath & Left(objFile.Name, InStr(1, objFile.Name, ".") - 1)
.Close
End With
Set p = Nothing
End If
Next
End If
答案 1 :(得分:2)
答案 2 :(得分:2)
是的,你可以在PowerPoint中使用这样的东西:
Sub CreatePresWithImage()
Dim i As Integer
Dim imagePath As String
Dim savePath As String
imagePath = "C:\Documents and Settings\XPMUser\My Documents\My Pictures\"
savePath = "C:\Documents and Settings\XPMUser\My Documents\"
Dim p As Presentation
For i = 0 To 999
Set p = Presentations.Add(msoFalse)
With p
.Slides.Add Index:=1, Layout:=ppLayoutBlank
.Slides(1).Shapes.AddPicture FileName:=imagePath & "HueTint-30.png", _
LinktoFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=10, Top:=10
.SaveAs savePath & "Sample" & i + 1
.Close
End With
Set p = Nothing
Next
End Sub
您需要管理图片部分(在.Slides(1).Shapes.AddPicture FileName:=
上方),以确保您每次都能获得所需的图片。在同一例程中,您可以设置图片大小(Width
和Height
- 它们是可选的)和位置(Left
和Top
)。