Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word documents got corrupt, too big 3

Status
Not open for further replies.

DavePL

IS-IT--Management
Sep 11, 2000
158
US
Several users on our network have word documents that got corrupt somehow, so that the file size is 1-4 MB. When the documents are copied and pasted on a blank document, they take up just 40 KB. This is taking a lot of excess space on the server.

We were wondering if there is a faster way to fix them, or do we have to go through them file-by-file?
 
You can loop through all the *.doc files in a directory with this macro. It opens the file, selects the whole document and copies it, then pastes to a new document. The file is then saved with the original name, but in a new directory.


Sub RecoverFile()
Dim strPath As String
Dim strNewPath As String
Dim strFullPathDoc As String
Dim strFileName As String


strPath = "F:\Data\TestFolder\"
strNewPath = strPath & "Recovered\"

strFullPathDoc = Dir(strPath & "*.doc", vbNormal)

Do While strFullPathDoc <> &quot;&quot;
strFileName = ExtractFileName(strFullPathDoc)

Documents.Open strPath & strFileName

Selection.WholeStory
Selection.Copy
Documents.Add Template:=&quot;Normal&quot;, NewTemplate:=False
Selection.Paste

ActiveDocument.SaveAs strNewPath & strFileName
ActiveWindow.Close

strFullPathDoc = Dir ' Get next entry.
Loop
End Sub

Function ExtractFileName(strFullPath As String)
Dim txt As String


On Error Resume Next

txt = &quot;&quot; & strFullPath

While InStr(txt, &quot;\&quot;) > 0
txt = Mid$(txt, InStr(txt, &quot;\&quot;) + 1)
Wend

If InStr(txt, &quot;:&quot;) > 0 Then
txt = Mid$(txt, InStr(txt, &quot;:&quot;) + 1)
End If

ExtractFileName = txt
End Function

 
Much appreicated. That does look like a big time saver. I will next learn how to use it!
 
GeekGirlau,

I ALSO want to give my THANKS !!!

While I don't have a use for this right at the moment, I'm sure it will be VERY useful to have on hand - in my &quot;library of useful solutions&quot;.

You might want to consider creating a &quot;FAQ&quot; for this.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top