Hi all!
I've been working on a macro (in excel) to remove document information/ from all the powerpoint, excel, and word files within a document, but I'm having a difficult time getting the .RemoveDocumentInformation(type) method to run with any non-excel types. The code will run if I replace the type with an excel type. Has anybody had any experience with this? The following is my in-progress code for Excel 2007.
I've been working on a macro (in excel) to remove document information/ from all the powerpoint, excel, and word files within a document, but I'm having a difficult time getting the .RemoveDocumentInformation(type) method to run with any non-excel types. The code will run if I replace the type with an excel type. Has anybody had any experience with this? The following is my in-progress code for Excel 2007.
Code:
Sub CleanPersonalInfo()
'Macro for cleaning personal data from files within selected folder.
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim WordFile As Object
Dim PowerPointFile As Object
Dim FolderPath As FileDialog
Dim FolderName As String
Dim DocType As String
Dim CurrentFile As String
Set WordFile = CreateObject("Word.Application")
Set PowerPointFile = CreateObject("PowerPoint.Application")
''''''''''''''''''''''''''''''''''''''''''''''
Set FolderPath = Application.FileDialog(msoFileDialogFolderPicker)
With FolderPath
.AllowMultiSelect = False
.Show
FolderName = .SelectedItems(1)
End With
''''''''''''''''''''''''''''''''''''''''''''''
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(FolderName)
Set objFiles = objFolder.Files
For Each objF1 In objFiles
CurrentFile = objF1.Path
Select Case Right(objF1.Name, 4)
Case ".xls", "xlsx", "xlsm" ': DocType = "xlRDIAll"
Workbooks.Open (CurrentFile)
With ActiveWorkbook
.RemoveDocumentInformation (xlRDIAll)
.Save
.Close
End With
Case ".doc", "docx", "docm" ': DocType = "wdRDIAll"
WordFile.documents.Open (CurrentFile)
With WordFile.ActiveDocument
.RemoveDocumentInformation (wdRDIAll)
.ActiveDocument.Save
.ActiveDocument.Close
End With
Case ".ppt", "pptx", "pptm" ': DocType = "ppRDIAll"
PowerPointFile.Visible = True
PowerPointFile.Presentations.Open (CurrentFile)
With PowerPointFile.ActivePresentation
.RemoveDocumentInformation (ppRDIAll)
.Save
.Close
End With
End Select
Next
Set objF1 = Nothing: Set objFiles = Nothing: Set objFolder = Nothing: Set objFS = Nothing
ExcelFile.Quit
WordFile.Quit
PowerPointFile.Quit
End Sub