A family of Microsoft word processing software products for creating web, email, and print documents.
Thanks so much for this!
We were able to use this as a base and edited it to include the headers and footers and go through folders and subfolder to check the documents. I would not have gone this route on VBA without your help! For some reason in my manual testing ctrl A and unchecking the button would result in the neutral box instead of it being unchecked but the code provided leaves it unchecked and removes it entirely.
This is the code we ended up getting to work (I have zero formal experience coding so it may be rough or there may be a better way, but this worked for our purposes):
Sub UncheckNoProofingInFolder()
' Charles Kenyon 2025-02-25
' Removes "No Proofing" from text in main body, headers, and footers
' Processes .doc and .docx files in a folder and its subfolders
'
Dim folderPath As String
' Prompt the user to select a folder
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Folder"
.AllowMultiSelect = False
If .Show = -1 Then ' If the user selects a folder
folderPath = .SelectedItems(1) & "\"
Else
MsgBox "No folder selected. Macro will exit."
Exit Sub
End If
End With
' Call the recursive function to process the folder and subfolders
ProcessFolder folderPath
MsgBox "All documents have been processed successfully."
End Sub
Sub ProcessFolder(folderPath As String)
Dim fileName As String
Dim subfolder As String
Dim doc As Document
' Process all .docx files in the current folder
fileName = Dir(folderPath & "\*.docx")
On Error GoTo ErrorInDoc
Do While fileName <> ""
' Open the document
Set doc = Documents.Open(folderPath & fileName)
' Remove "No Proofing" from main body, headers, and footers
RemoveNoProofing doc
' Save and close the document
doc.Save
doc.Close
' Move to the next file
fileName = Dir
Loop
' Process all .doc files in the current folder
fileName = Dir(folderPath & "\*.doc")
Do While fileName <> ""
' Open the document
Set doc = Documents.Open(folderPath & fileName)
' Remove "No Proofing" from main body, headers, and footers
RemoveNoProofing doc
' Save and close the document
doc.Save
doc.Close
' Move to the next file
fileName = Dir
Loop
' Check for subfolders and process them
subfolder = Dir(folderPath & "\*", vbDirectory)
Do While subfolder <> ""
If subfolder <> "." And subfolder <> ".." Then
If (GetAttr(folderPath & subfolder) And vbDirectory) = vbDirectory Then
' Call ProcessFolder recursively for each subfolder
ProcessFolder folderPath & subfolder & "\"
End If
End If
subfolder = Dir
Loop
Exit Sub
ErrorInDoc:
MsgBox "There was an error processing the document: " & fileName
On Error GoTo -1
End Sub
Sub RemoveNoProofing(doc As Document)
Dim headerFooter As headerFooter
Dim section As section
' Remove "No Proofing" from the main body
doc.Content.NoProofing = False
' Remove "No Proofing" from headers and footers
For Each section In doc.Sections
For Each headerFooter In section.Headers
headerFooter.Range.NoProofing = False
Next headerFooter
For Each headerFooter In section.Footers
headerFooter.Range.NoProofing = False
Next headerFooter
Next section
End Sub