F
ferdberfel
hello,
I'm trying to write a macro to take the images in a powerpoint
presentation and save them to a separate folder. I recorded a macro
to see how it's done and I got this:
Sub Macro3()
ActiveWindow.Selection.SlideRange.Shapes("Picture 16").Select
ActivePresentation.SaveAs FileName:="C:\Documents and Settings
\username\My Documents\My Pictures\Picture1.jpg",
FileFormat:=ppSaveAsJPG, EmbedTrueTypeFonts:=msoFalse
End Sub
works great. just like I expected - I selected an image - right
clicked, picked "Save as Picture" . excellent.
so then I wanted to loop through all slides, and loop through all
shapes on each slide.... if it's an image, save it. However what
happens is for every single slide, the "ActivePresentation.SaveAs" ...
saves EVERY single SLIDE as a jpeg... and I don't even have the
selected image as a separate entity, just the whole slide... here's
that code:
any ideas would be greatly appreciated! Thanks in advance!
(Powerpoint 2003) (Windows XP 5.1 SP3)
Sub ExportAllImages()
Dim thePresentation As Presentation
Dim theSlides As Slides
Dim curSlide As Slide
Dim curShape As Shape
Dim CurrentPageName As String
Dim CurrentPageNumber As Integer
Dim CurrentFileIndex As Integer
On Error GoTo ErrorHandler
Set thePresentation = ActivePresentation
Set theSlides = thePresentation.Slides
CurrentPageNumber = 0
For Each curSlide In theSlides 'get every single slide
CurrentPageNumber = CurrentPageNumber + 1
' go to each slide
For Each curShape In curSlide.Shapes ' inspect every shape
CurrentFileIndex = 1
If curShape.Type = 13 Then
'curShape.Select
ActiveWindow.Selection.SlideRange.Shapes(curShape.Name).Select
MsgBox "did I select the Picture [" & curShape.Name &
"] ?"
fname = thePresentation.Path & "\" & "stuff\Page" &
CurrentPageNumber & "_" & CurrentFileIndex & ".jpg"
Debug.Print "Please wait ….. saving [" & fname & "]"
ActivePresentation.SaveAs FileName:=fname,
FileFormat:=ppSaveAsJPG, EmbedTrueTypeFonts:=msoFalse
CurrentFileIndex = CurrentFileIndex + 1
Debug.Print "back from saving image"
End If
Debug.Print "Please wait getting next shape"
Next curShape
'Exit Sub '---- uncomment this to just let it operate on 1
slide, otherwise it will seemingly go away for ever while it tries to
save ALL slides, everytime.
Next curSlide
MsgBox "Done! "
Exit Sub
ErrorHandler:
MsgBox "oops: error : " & Err.Description & " curShape.Name = " &
curShape.Name
End Sub
I'm trying to write a macro to take the images in a powerpoint
presentation and save them to a separate folder. I recorded a macro
to see how it's done and I got this:
Sub Macro3()
ActiveWindow.Selection.SlideRange.Shapes("Picture 16").Select
ActivePresentation.SaveAs FileName:="C:\Documents and Settings
\username\My Documents\My Pictures\Picture1.jpg",
FileFormat:=ppSaveAsJPG, EmbedTrueTypeFonts:=msoFalse
End Sub
works great. just like I expected - I selected an image - right
clicked, picked "Save as Picture" . excellent.
so then I wanted to loop through all slides, and loop through all
shapes on each slide.... if it's an image, save it. However what
happens is for every single slide, the "ActivePresentation.SaveAs" ...
saves EVERY single SLIDE as a jpeg... and I don't even have the
selected image as a separate entity, just the whole slide... here's
that code:
any ideas would be greatly appreciated! Thanks in advance!
(Powerpoint 2003) (Windows XP 5.1 SP3)
Sub ExportAllImages()
Dim thePresentation As Presentation
Dim theSlides As Slides
Dim curSlide As Slide
Dim curShape As Shape
Dim CurrentPageName As String
Dim CurrentPageNumber As Integer
Dim CurrentFileIndex As Integer
On Error GoTo ErrorHandler
Set thePresentation = ActivePresentation
Set theSlides = thePresentation.Slides
CurrentPageNumber = 0
For Each curSlide In theSlides 'get every single slide
CurrentPageNumber = CurrentPageNumber + 1
' go to each slide
For Each curShape In curSlide.Shapes ' inspect every shape
CurrentFileIndex = 1
If curShape.Type = 13 Then
'curShape.Select
ActiveWindow.Selection.SlideRange.Shapes(curShape.Name).Select
MsgBox "did I select the Picture [" & curShape.Name &
"] ?"
fname = thePresentation.Path & "\" & "stuff\Page" &
CurrentPageNumber & "_" & CurrentFileIndex & ".jpg"
Debug.Print "Please wait ….. saving [" & fname & "]"
ActivePresentation.SaveAs FileName:=fname,
FileFormat:=ppSaveAsJPG, EmbedTrueTypeFonts:=msoFalse
CurrentFileIndex = CurrentFileIndex + 1
Debug.Print "back from saving image"
End If
Debug.Print "Please wait getting next shape"
Next curShape
'Exit Sub '---- uncomment this to just let it operate on 1
slide, otherwise it will seemingly go away for ever while it tries to
save ALL slides, everytime.
Next curSlide
MsgBox "Done! "
Exit Sub
ErrorHandler:
MsgBox "oops: error : " & Err.Description & " curShape.Name = " &
curShape.Name
End Sub