Hello forum,
I am a newbie both to these forums and to VBA, pleased to make your acquaintance.
Using a mix of inept abilities and code found online, I have been trying to create a Powerpoint macro that should:
- Open a file dialog and allow you to select a number of PPT(X) files from a folder (or subfolders, through Search)
- Process each file and fit all text to their corresponding shapes
I have gotten pretty far - the below seems to work when stepping through the macro, and the fit-text-to-shape bit works well in individual files.
But I must be doing something wrong as running the macro in full yields no results (although each files is saved).
I'm at my wits' end here, any help or advice would be much appreciated.
Thanks!
Sub FitTextToShapes()
Dim oSl As Slide
Dim oSh As Shape
Dim fd As FileDialog
Dim FileChosen As Integer
Dim vrtSelectedItem As Variant
Dim Current As Presentation
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = True
fd.Filters.Add "PPT(X) files", "*.ppt*", 1
FileChosen = fd.Show
If FileChosen = -1 Then
With fd
For Each vrtSelectedItem In .SelectedItems
Set Current = Presentations.Open(vrtSelectedItem)
Current.Windows(1).Activate
With ActivePresentation
For Each oSl In .Slides
For Each oSh In oSl.Shapes
With oSh
If .HasTextFrame Then
If .TextFrame.HasText Then
.TextFrame2.AutoSize = msoAutoSizeTextToFitShape
End If
End If
End With
Next
Next
End With
ActivePresentation.Save
ActivePresentation.Close
Next
End With
End If
MsgBox ("Done!")
End Sub