Previous  Home  Next

Mass Quantities

This is the code from the Mass Quantities section of the seminar (modMassQuantities) that deals with automating actions across many slides or many presentations.

Option Explicit

Sub GreenToRed()
    ' Object variables for Slides and Shapes
    Dim oSh As Shape
    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If oSh.Fill.ForeColor.RGB = RGB(0, 255, 0) Then
                oSh.Fill.ForeColor.RGB = RGB(255, 0, 0)
            End If
        Next oSh
    Next oSl

End Sub

Sub FolderFull()
    ' For each presentation in a folder that matches our specifications
    '   - open the file
    '   - call another subroutine that does something to it
    '   - save the file
    '   - close the file

    Dim strCurrentFile As String    ' variable to hold a single file name
    Dim strFileSpec As String       ' variable to hold our file spec
    ' give it a value that works for my computer:
    strFileSpec = "C:\Documents and Settings\Stephen Rindsberg\Desktop\PPTLive\Automation\LotsOfFiles\*.ppt"

    ' get the first file that matches our specification
    strCurrentFile = Dir$(strFileSpec)

    ' don't do anything if we didn't find any matching files
    ' but if we did, keep processing files until we don't find any more
    While Len(strCurrentFile) > 0
        ' open the presentation
        Presentations.Open (strCurrentFile)

        ' by changing this next line to call a different subroutine
        ' you can have this same code do other tasks
        Debug.Print ActivePresentation.Name

        ' call the Green to Red macro to process the file
        Call GreenToRed

        ' save the file under a new name with FIXED_ at the beginning
        ActivePresentation.SaveAs (ActivePresentation.Path & "\" _
            & "Fixed_" _
            & ActivePresentation.Name)

        ' close it
        ' and get the next file that matches our specification
        ' if you don't supply a new file spec, Dir$ returns the next
        ' file that matches the previously supplied specification
        strCurrentFile = Dir$

    ' Note: Don't use Dir in code that's called from within a loop
    ' that uses Dir - only one "Dir" can be "active" at a time.
    ' In production code, it's best to keep it in a very short loop or
    ' to collect file names in a short loop then process them after
    ' Arrays are useful for this

End Sub

Click Next to continue

Previous  Home  Next