Log in

View Full Version : macro for filename and path in footer



nathaly
05-07-2009, 01:13 AM
Hello,

I found a macro online to put the filename and path in the footer of each slide in a presentation. But there is a error.
Can somebody help me?



Sub UpdatePath()
' Macro to add the path and file name to each slide's footer.
Dim PathAndName As String
Dim FeedBack As Integer
' Place a message box warning prior to replacing footers.
FeedBack = MsgBox( _
"This Macro replaces any existing text that appears " & _
"within your current footers " & Chr(13) & _
"with the presentation name and its path. " & _
"Do you want to continue?", vbQuestion + vbYesNo, _
"Warning!")
' If no is selected in the dialog box, quit the macro.
If FeedBack = vbNo Then
End
End If
' Gets the path and file name and converts the string to lowercase.
PathAndName = LCase(ActivePresentation.Path & "\" & _
ActivePresentation.Name)
' Checks whether there is a Title Master, and if so, updates the
' path.
If ActivePresentation.HasTitleMaster Then
With ActivePresentation.TitleMaster.HeadersFooters
With .Footer
.Text = PathAndName
End With
End With
End If
' Updates the slide master.
With ActivePresentation.SlideMaster.HeadersFooters
With .Footer
.Text = PathAndName
End With
End With
' Updates the individual slides that do not follow the master.
Dim X As Integer
For X = 1 To ActivePresentation.Slides.Count
With ActivePresentation.Slides(X).HeadersFooters
With .Footer
.Text = PathAndName
End With
End With
Next

End Sub


Many thanks,

Nathaly

Cosmo
05-07-2009, 05:33 AM
It looks like you're in version 2007, I only get the error in that version (2003 works fine). Not sure what the error is, it compiles correctly and the code suggests that there is nothing wrong (the object is a valid object from what I can tell), but putting an error handler around that line will suppress the error.
For X = 1 To ActivePresentation.Slides.Count
On Error Resume Next
ActivePresentation.Slides(X).HeadersFooters.Footer.Text = PathAndName
On Error GoTo 0
Next

nathaly
05-07-2009, 05:47 AM
Hello,

Indeed I'm using a powerpoint 2007.
I just pasted your code after the entire code i already put in.
But now I got another error message.

Compile error:
For control variable already in use

How can I solve that?

Greetz,
Nathaly

nathaly
05-07-2009, 05:52 AM
Sorry already found the answer
But it's quiet strange because I don't get the filename and path into the footer. :-(

Grtz,
Nathaly

Cosmo
05-07-2009, 06:10 AM
Set the footer's visibility to true
Sub UpdatePath()
' Macro to add the path and file name to each slide's footer.
Dim PathAndName As String
Dim FeedBack As Integer
' Place a message box warning prior to replacing footers.
FeedBack = MsgBox( _
"This Macro replaces any existing text that appears " & _
"within your current footers " & Chr(13) & _
"with the presentation name and its path. " & _
"Do you want to continue?", vbQuestion + vbYesNo, _
"Warning!")
' If no is selected in the dialog box, quit the macro.
If FeedBack = vbNo Then
End
End If
' Gets the path and file name and converts the string to lowercase.
PathAndName = LCase(ActivePresentation.Path & "\" & _
ActivePresentation.Name)
' Checks whether there is a Title Master, and if so, updates the
' path.
If ActivePresentation.HasTitleMaster Then
With ActivePresentation.TitleMaster.HeadersFooters.Footer
.Text = PathAndName
.Visible = msoCTrue
End With
End If
' Updates the slide master.
With ActivePresentation.SlideMaster.HeadersFooters.Footer
.Text = PathAndName
.Visible = msoCTrue
End With
' Updates the individual slides that do not follow the master.
Dim X As Integer
For X = 1 To ActivePresentation.Slides.Count
On Error Resume Next
With ActivePresentation.Slides(X).HeadersFooters.Footer
.Text = PathAndName
.Visible = msoCTrue
End With
On Error GoTo 0
Next X

End Sub

nathaly
05-07-2009, 06:23 AM
It's solved!

Many thankx
Nathaly