Wednesday, August 31, 2011

Rebuild your Active Document

Your document is corrupt, or it is so heavily edited that it is behaving badly.
Use the little macro "RebuildActiveDocument" to grab all your text, unformatted, and rebuild the document.
CAUTION: make a copy of your document using Windows Explorer before running this macro.

Sub RebuildActiveDocument()

' Get the name of the source ActiveDocumentument
Dim strFilename As String
strFilename = ActiveDocument.FullName
' Get the stoty-content of the ActiveDocumentument
Dim strStoryContent As String
Dim lng As Long
For lng = 1 To ActiveDocument.StoryRanges.Count
strStoryContent = strStoryContent & ActiveDocument.StoryRanges(lng).Text
Next lng
' Close the ActiveDocumentument WITHOUT saving changes
ActiveDocument.Close (wdDoNotSaveChanges)
' Create a new ActiveDocumentument
' Insert the text file
Selection.TypeText (strStoryContent)
' Save the ActiveDocumentument with the original name
ActiveDocument.SaveAs (strFilename)
End Sub

No comments:

Post a Comment