Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to delete macros from thousands of files?
I need to find a way to delete all the macros from several thousand Word and
Excel files in one operation. Is there a way to do this? (Please bear in mind that I am severely programming-impaired. Type slowly and loudly!) -- FinnLisa |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to delete macros from thousands of files?
Excel questions should be addressed to the Excel forums.
Are you sure the macros are stored in the documents and not in the document template? Which Word version? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org FinnLisa wrote: I need to find a way to delete all the macros from several thousand Word and Excel files in one operation. Is there a way to do this? (Please bear in mind that I am severely programming-impaired. Type slowly and loudly!) |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to delete macros from thousands of files?
Yes, they're in the documents themselves, which are mostly Word 2003 but
could be in other versions as well. -- FinnLisa "Graham Mayor" wrote: Excel questions should be addressed to the Excel forums. Are you sure the macros are stored in the documents and not in the document template? Which Word version? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org FinnLisa wrote: I need to find a way to delete all the macros from several thousand Word and Excel files in one operation. Is there a way to do this? (Please bear in mind that I am severely programming-impaired. Type slowly and loudly!) |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to delete macros from thousands of files?
One possibilty is to save as RTF which does not support macros. The
following will do that. *May I suggest that you copy the documents into a folder and run the macro on copies of the documents in case there are some formatting anomalies.* Although Word will open RTF docs without problem, you may then wish to change the line oDoc.SaveAs strPath & strFileName, wdFormatRTF to oDoc.SaveAs strPath & strFileName, wdFormatDocument and re-run the macro to save all as Word document format - without the macros. Sub BatchProcess() Dim strFileName As String Dim strPath As String Dim oDoc As Document Dim fDialog As FileDialog Set fDialog = Application.FileDialog(msoFileDialogFolderPicker) With fDialog .Title = "Select folder and click OK" .AllowMultiSelect = False .InitialView = msoFileDialogViewList If .Show -1 Then MsgBox "Cancelled By User", , _ "List Folder Contents" Exit Sub End If strPath = fDialog.SelectedItems.Item(1) If Right(strPath, 1) "\" _ Then strPath = strPath + "\" End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(strPath, 1) = Chr(34) Then strPath = Mid(strPath, 2, Len(strPath) - 2) End If strFileName = Dir$(strPath & "*.doc") While Len(strFileName) 0 Set oDoc = Documents.Open(strPath & strFileName) Application.DisplayAlerts = wdAlertsNone oDoc.SaveAs strPath & strFileName, wdFormatRTF Application.DisplayAlerts = wdAlertsAll oDoc.Close SaveChanges:=wdDoNotSaveChanges strFileName = Dir$() Wend End Sub Another method uses some code I borrowed from an on-line source to delete the macros individually from the document. This has the advantage of minimizing any formatting anomalies. In order to run this macro, you will need to add a reference to Microsoft Visual Basic for Applications Extensibility from the vba editor tools options Sub BatchProcess() Dim strFileName As String Dim strPath As String Dim oDoc As Document Dim VBComps As VBComponents Dim VBComp As VBComponent Dim fDialog As FileDialog Set fDialog = Application.FileDialog(msoFileDialogFolderPicker) With fDialog .Title = "Select folder and click OK" .AllowMultiSelect = False .InitialView = msoFileDialogViewList If .Show -1 Then MsgBox "Cancelled By User", , _ "List Folder Contents" Exit Sub End If strPath = fDialog.SelectedItems.Item(1) If Right(strPath, 1) "\" _ Then strPath = strPath + "\" End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(strPath, 1) = Chr(34) Then strPath = Mid(strPath, 2, Len(strPath) - 2) End If strFileName = Dir$(strPath & "*.doc") While Len(strFileName) 0 Set oDoc = Documents.Open(strPath & strFileName) Set VBComps = ActiveDocument.VBProject.VBComponents For Each VBComp In VBComps Select Case VBComp.Type Case vbext_ct_StdModule, _ vbext_ct_MSForm, _ vbext_ct_ClassModule VBComps.Remove VBComp Case Else With VBComp.CodeModule .DeleteLines 1, .CountOfLines End With End Select Next VBComp oDoc.Close SaveChanges:=wdSaveChanges strFileName = Dir$() Wend End Sub Again I recommend running the macro on COPIES of the documents. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org FinnLisa wrote: Yes, they're in the documents themselves, which are mostly Word 2003 but could be in other versions as well. Excel questions should be addressed to the Excel forums. Are you sure the macros are stored in the documents and not in the document template? Which Word version? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org FinnLisa wrote: I need to find a way to delete all the macros from several thousand Word and Excel files in one operation. Is there a way to do this? (Please bear in mind that I am severely programming-impaired. Type slowly and loudly!) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How To Convert Thousands of Works 7.0 Files to Word 2007 Simultaneously | Microsoft Word Help | |||
Delete Macros | Microsoft Word Help | |||
delete macros in word | Microsoft Word Help | |||
How do I define thousands separator for a mergefield? | Mailmerge | |||
thousands separator in WORD? | Tables |