Close All Temporary Files

Displaying information in a temporary file is useful technique. The user can review the temporary file and when necessary save it. Small displays can be sent directly to the screen but large displays should be sent to a temporary file. To assist the user it is also important to be able to quickly remove all of these temporary files. It helps that for each application all temporary file names start with the same character string.

The VBA macro code to obtain the opened files is similar in the three Microsoft application, Excel, Word and PowerPoint. VBA has a macro variable to indicate the active application. The only difference is one key word in the 'For' statement. Excel uses the key word 'Workbooks', Word uses the key word 'Documents' and PowerPoint uses key word 'Presentations'. To list the opened files try Files opened

PowerPoint macro is repeated a few times to close all the temporary Presentations since the close statement affects the looping.

VBA Fifth Dimension Macro-CLOSE_FILES

Review the following code, copy it to Excel or Word and execute it.

Sub CLOSE_FILES()
    If InStr(Application.Name, "Excel") Then
       For Each FILE_NAME In Workbooks
           If Left(FILE_NAME.Name, 4) = "Book" Then
              FILE_NAME.Saved = True
              FILE_NAME.Close
           End If
       Next
    End If
    If InStr(Application.Name, "PowerPoint") Then
       For II = 1 To 5
       For Each FILE_NAME In Presentations
           If Left(FILE_NAME.Name, 12) = "Presenation" _ 
           Then FILE_NAME.Close
       Next
       Next
    End If
    If InStr(Application.Name, "Word") Then
       For Each FILE_NAME In Documents
           If Left(FILE_NAME.Name, 8) = "Document" Then
              FILE_NAME.Saved = True
              FILE_NAME.Close
           End If
       Next
    End If
End Sub