Microsoft KB Archive/278544

= No warning when you overwrite PowerPoint 2002 files in Visual Basic for Applications =

Article ID: 278544

Article Last Modified on 1/29/2007

-

APPLIES TO


 * Microsoft PowerPoint 2002 Standard Edition

-



This article was previously published under Q278544





SYMPTOMS
When you save a Microsoft PowerPoint 2002 file by using the Save or SaveAs methods in Microsoft Visual Basic for Applications (VBA), you do not receive any warning if the file overwrites an existing file with the same name.

This behavior differs from other Microsoft Office programs that warn you in this case.



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: The following macro examples work only in PowerPoint. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, click the following article number to view the article in the Microsoft Knowledge Base: To work around this problem, use either of the following methods:


 * Save the file by using only the PowerPoint object model.
 * Save the file by using the FileSystemObject.

Save the File by Using Only the PowerPoint Object Model
The following sample macro checks whether or not the file name you are about to save exists, and prompts you with a warning if it does. To create the macro, follow these steps:  On the Tools menu, point to Macro, and then click Visual Basic Editor. On the Insert menu, click Module.  Type the following code in the module: Function VerifyFilename(strFilename As String) As Boolean

On Error Resume Next

Dim strPath        As String Dim strFile        As String Dim i              As Long Dim strNextFile    As String '  ' Get the path from the file name. '  For i = Len(strFilename) To 1 Step -1 If Mid(strFilename, i, 1) = &quot;\&quot; Then strPath = Left(strFilename, i)        strFile = Right(strFilename, Len(strFilename) - i)         Exit For End If  Next i   ' ' Set the flag to True. '  VerifyFilename = True '  ' Start listing all the files in the SaveAs Path. '  strNextFile = Dir(strPath) '  ' Loop though all files in that folder. '  Do Until strNextFile = &quot;&quot; If LCase(strNextFile) = LCase(strFile) Then '  ' If the file is found, set the flag to False and exit. '        VerifyFilename = False Exit Function End If

strNextFile = Dir

Loop End Function

Sub SaveFile Dim bolVerify As Boolean Dim Msg As String Dim Style As Long Dim Title As String Dim Response As String Dim MyString As String

With ActivePresentation bolVerify = VerifyFilename(.FullName)

If bolVerify = False Then '  ' Define success message. '        Msg = &quot;You're about to overwrite &quot; & .FullName & _ &quot;Do you want to continue ?&quot; '  ' Define buttons for message box. '        Style = vbYesNo + vbCritical + vbDefaultButton2 '  ' Define the title for the message box. '        Title = &quot;FILE OVERWRITE WARNING!!!&quot; Response = MsgBox(Msg, Style, Title) '  ' User chose No and is sent to the end of the Sub without saving. '        If Response = vbYes Then ActivePresentation.Save MsgBox &quot;File Saved!&quot; End If     End If   End With End Sub 

Save the File by Using the FileSystemObject
The following sample macro uses the Microsoft Scripting Runtime library to verify that the file name is not in use in the folder that you choose. To create the macro, follow these steps:  On the Tools menu, point to Macro, and then click Visual Basic Editor. On the Tools menu, click References.</li> In the list of references, click to select the Microsoft Scripting Runtime check box. Click OK.</li> On the Insert menu, click Module.</li>  Type the following code in the module: Function SaveAsFile(strFullPath) As Boolean Dim fsoFile As FileSystemObject Dim msgResults As VbMsgBoxResult '  ' Set fsoFile to the Microsoft Scripting Runtime FileSystemObject. '  Set fsoFile = CreateObject(&quot;scripting.filesystemobject&quot;) '  ' Initialize the return value of the function to True. '  SaveAsFile = True

With ActivePresentation '  ' Check to see if the file name exists at the file destination folder. ' If it does, then ask the user if they want to overwrite the ' existing file or not. '     If fsoFile.FileExists(strFullPath) Then msgResults = MsgBox(&quot;Warning! File: &quot; & strFullPath & &quot; exists!&quot; _              & vbNewLine & &quot;Overwrite?&quot;, vbYesNo, &quot;File Exists&quot;) '  ' If the answer is yes, overwrite the file. '        If msgResults = vbYes Then .SaveAs strFullPath Else SaveAsFile = False End If  ' ' If the file does not exist at the destination folder, save it. '     Else .SaveAs strFullPath End If  End With '  ' Clear the fsoFile object. '  Set fsoFile = Nothing End Function

Sub SaveFile Dim strPresentationPath As String Dim bSaved As Boolean

'  ' Prompt user for the location to save the file. '  strPresentationPath = InputBox(&quot;Enter path and name to save file as:&quot;, _         &quot;Save as new File&quot;, ActivePresentation.FullName) '  ' Call the SaveFileAs function with the file location and name. '  bSaved = SaveAsFile(strPresentationPath) '  ' If it saved, tell the user. If it didn't, tell the user that too. '  If bSaved Then MsgBox &quot;Saved Presentation: &quot; & strPresentationPath Else MsgBox &quot;Presentation, &quot; & strPresentationPath & &quot;, was not saved.&quot; End If End Sub </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: PPT2002 PPT alert error warning message

Keywords: kbbug kbnofix KB278544

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.