EDN Admin
Well-known member
Hi all,<br/>
<br/>
I have an add-in which saves out different packs of slides from a master slides template. When you click on a macro button the macro automatically saves out the pack with the specified name of that related pack and uses text that has been entered on the first
slide in a text box in the naming convention of the filename.<br/>
<br/>
All I am after is a simple way to stop users from saving over the same file if it has already been saved before. So I need some form of validation that checks to see whether the file exists...if it does then implement a version number to the filename and if
it does not then save it like normal.<br/>
<br/>
Here is my code:<br/>
<br/>
Option Explicit<br/>
<br/>
Public Sub CreatePack(control As IRibbonControl)<br/>
<br/>
Dim packName As String<br/>
Select Case control.Id<br/>
Case "packbutton_B1"<br/>
packName = "B1"<br/>
Case "packbutton_B2"<br/>
packName = "B2"<br/>
Case "packbutton_TSD"<br/>
packName = "TSD"<br/>
End Select<br/>
<br/>
Note: Attempt to remove characters that are not file-system friendly<br/>
Dim Title As String<br/>
If ActivePresentation.Slides(1).Shapes.Count >= 9 Then<br/>
Title = Trim(ActivePresentation.Slides(1).Shapes(9).TextEffect.Text)<br/>
If Title = "" Then MsgBox "Warning: A project title has not been entered on Slide 1."<br/>
Else<br/>
Title = "(Project Title Not Known)"<br/>
MsgBox "The title slide has been removed, the project name cannot be detected."<br/>
End If<br/>
Title = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Title, "/", ""), "", ""), ":", ""), "*", ""), "<", ""), ", ""), "|", ""), """", "")<br/>
<br/>
Dim path As String<br/>
path = ActivePresentation.path<br/>
<br/>
If MsgBox("This will produce a pack in a separate PowerPoint file. Before extracting the pack make sure you have implemented a version number otherwise your changes maybe overwritten." & vbCrLf & vbCrLf & "Your current file will remain open, and
any pending changes will not be automatically saved.", vbOKCancel, "Slide Manager - Create Pack") = vbOK Then<br/>
<br/>
<br/>
CopySlidesToBlankPresentation packName<br/>
<br/>
Application.ActivePresentation.SaveAs path & "" & packName & " Slide Pack - " & Title, ppSaveAsOpenXMLPresentation<br/>
<br/>
ActivePresentation.Save<br/>
<br/>
Else<br/>
<br/>
End If<br/>
<br/>
End Sub
View the full article
<br/>
I have an add-in which saves out different packs of slides from a master slides template. When you click on a macro button the macro automatically saves out the pack with the specified name of that related pack and uses text that has been entered on the first
slide in a text box in the naming convention of the filename.<br/>
<br/>
All I am after is a simple way to stop users from saving over the same file if it has already been saved before. So I need some form of validation that checks to see whether the file exists...if it does then implement a version number to the filename and if
it does not then save it like normal.<br/>
<br/>
Here is my code:<br/>
<br/>
Option Explicit<br/>
<br/>
Public Sub CreatePack(control As IRibbonControl)<br/>
<br/>
Dim packName As String<br/>
Select Case control.Id<br/>
Case "packbutton_B1"<br/>
packName = "B1"<br/>
Case "packbutton_B2"<br/>
packName = "B2"<br/>
Case "packbutton_TSD"<br/>
packName = "TSD"<br/>
End Select<br/>
<br/>
Note: Attempt to remove characters that are not file-system friendly<br/>
Dim Title As String<br/>
If ActivePresentation.Slides(1).Shapes.Count >= 9 Then<br/>
Title = Trim(ActivePresentation.Slides(1).Shapes(9).TextEffect.Text)<br/>
If Title = "" Then MsgBox "Warning: A project title has not been entered on Slide 1."<br/>
Else<br/>
Title = "(Project Title Not Known)"<br/>
MsgBox "The title slide has been removed, the project name cannot be detected."<br/>
End If<br/>
Title = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Title, "/", ""), "", ""), ":", ""), "*", ""), "<", ""), ", ""), "|", ""), """", "")<br/>
<br/>
Dim path As String<br/>
path = ActivePresentation.path<br/>
<br/>
If MsgBox("This will produce a pack in a separate PowerPoint file. Before extracting the pack make sure you have implemented a version number otherwise your changes maybe overwritten." & vbCrLf & vbCrLf & "Your current file will remain open, and
any pending changes will not be automatically saved.", vbOKCancel, "Slide Manager - Create Pack") = vbOK Then<br/>
<br/>
<br/>
CopySlidesToBlankPresentation packName<br/>
<br/>
Application.ActivePresentation.SaveAs path & "" & packName & " Slide Pack - " & Title, ppSaveAsOpenXMLPresentation<br/>
<br/>
ActivePresentation.Save<br/>
<br/>
Else<br/>
<br/>
End If<br/>
<br/>
End Sub
View the full article