Strip Document

S

Sammy

Hi,

I have created a macro that will extract the text out of a corrupted or
messed up Word document and paste special unformatted into a new document
container (selecting everything except the last paragraph mark attached to
text). Of course the user has to reformat the new document. This is also
used for converting WordPerfect documents. I would like to be able to add
any existing Bold, Italic and Underline font formatting back into the new
document, as it was in the original document. I've tried a few things but no
success yet, for example entering "zzb" "zzi" and "zzu" before and after
formatted text in the original document but I'm really stuck on how this can
be done. Any ideas would be appreciated. Here's my cleanup macro (yes, all
my macros are really basic but I'm having fun learning VBA):

Sub CleanUp()
If Documents.Count = 0 Then Exit Sub

Selection.EndKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^$"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Cut
ActiveWindow.Close wdDoNotSaveChanges
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False
Selection.HomeKey Unit:=wdStory

End Sub

Thank you
 
D

Doug Robbins - Word MVP

Try

Dim BadDoc as Document
Dim NewDoc as Document
Dim rng as Range
Set BadDoc = ActiveDocument 'the corrupt document
Set rng = BadDoc.Range
rng.End = rng.End - 1
Set NewDoc = Documents.Add
NewDoc.Range.FormattedText = rng.FormattedText

That may bring over the bold, italic and underlined formatting.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Sammy

Hi Doug,

That worked but it brought over the paragraph formatting also which I am
trying to leave behind, I didn't want to bring over paragraph, style or
section formatting, just font formatting. I'm not sure how to change your
code to do that.


Thanks for helping me.
 
D

Doug Robbins - Word MVP

The code cannot be modified to do that. I thought that you were trying to
resurrect corrupt documents.

The easiest thing might be to then go through the new document setting the
formatting of the paragraphs, styles, etc to whatever you want it to be.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top