PPT converteren naar JPG in eigen map

  • Onderwerp starter Onderwerp starter SA3
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

SA3

Gebruiker
Lid geworden
3 jan 2016
Berichten
130
Onderstaande macro converteert PPT naar JPG. Echter alle JPG's komen in dezelfde output-map.
Hoe macro aan te passen zodat de JPG's (met de bestandsnaam van de PPT) worden weggeschreven in een eigen map met de naam van betreffende PPT?


Code:
Option Explicit

Public Sub PresentationsToImages()

    Dim lngPresentations As Long
    Dim strImageName As String
    Dim strImagePath As String
    Dim strPresentationName As String
    Dim strPresentationPath As String
    Dim objSlide As Object

    On Error Resume Next

    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Show
        For lngPresentations = 1 To .SelectedItems.Count
            strPresentationPath = .SelectedItems(lngPresentations)
            Presentations.Open strPresentationPath, msoTrue
            With ActivePresentation
                strPresentationName = Split(.Name, ".")(0)
                strImagePath = .path
                For Each objSlide In .Slides
                    With objSlide
                        strImageName = strPresentationName & "-" & Format(.SlideIndex, "000") & ".jpg"
                        .Export strImagePath & "\" & strImageName, "JPG"
                    End With
                Next
                .Close
            End With
        Next
    End With
    
    MsgBox "Presentations exported as images."
    
End Sub
 
Code:
Option Explicit

Public Sub PresentationsToImages()

    Dim lngPresentations As Long
    Dim strImageName As String
    Dim strImagePath As String
    Dim strPresentationName As String
    Dim strPresentationPath As String
    Dim objSlide As Object

    On Error Resume Next

    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Show
        For lngPresentations = 1 To .SelectedItems.Count
            strPresentationPath = .SelectedItems(lngPresentations)
            Presentations.Open strPresentationPath, msoTrue
            With ActivePresentation
                strPresentationName = Split(.Name, ".")(0)
               [COLOR=#ff0000] strImagePath = .Path & "\" & strPresentationName
                If Dir(strImagePath, vbDirectory) = "" Then
                    MkDir strImagePath
                End If[/COLOR]
                For Each objSlide In .Slides
                    With objSlide
                        strImageName = strPresentationName & "-" & Format(.SlideIndex, "000") & ".jpg"
                        .Export strImagePath & "\" & strImageName, "JPG"
                    End With
                Next
                .Close
            End With
        Next
    End With

    MsgBox "Presentations exported as images."

End Sub
Gemaakt en getest met window11en en office2007nl.
Code kwam me bekend voor ;), zie https://www.helpmij.nl/forum/showth...d-in-1-actie?p=6015275&viewfull=1#post6015275
 
Laatst bewerkt:
Klopt. Jouw code kreeg ik in 2017. Deze toevoeging werkt als een speer. Hartelijk dank.
 
Waarom aparte directories voor 100% identificeerbare bestanden ? Google is groot geworden door van dat concept af te stappen.

Wellicht loopt deze sneller:
Code:
Sub M_snb()
  With Application.FileDialog(1)
    .AllowMultiSelect = True
    .InitialFileName = "G:\Powerpoint\*.ppt"
    .Show
    For Each it In .SelectedItems
      With GetObject(it)
        For Each it1 In .slides
         it1.Export .Path & "" & .Name & Format(it1.slideIndex, "_000") & ".jpg", "jpg"
        Next
       .Close
     End With
   Next
  End With
End Sub
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan