Removing Frames

J

je7383

Good Afternoon!
I'm trying to create a script in Word 2003 that would remove all of the
frames in a document while retaining the text and formatting.

The following creates a new document, cycles through all the frame objects
in the original document, and is supposed to copy the text and formatting
from each frame to the new document.

It almost works! it works on most of the frames in the document, but some
entire frames are copied instead of just the text. Here's what it looks like:

Sub DelFrames()
Dim FrameCounter As Integer
Documents.Add
Documents(2).Activate
For FrameCounter = 1 To ActiveDocument.Frames.Count
'ActiveDocument.Frames(FrameCounter).Select
ActiveDocument.Frames(FrameCounter).Range.Select
Selection.Copy
Documents(1).Activate
Selection.Paste
Documents(2).Activate
ActiveDocument.Frames(FrameCounter).Select
Selection.CopyFormat
Documents(1).Activate
Selection.PasteFormat
ActiveDocument.Paragraphs.Add
Selection.Next(Unit:=wdParagraph, Count:=1).Select
Documents(2).Activate
Next FrameCounter

End Sub

Is there an easier way to convert all of the frames in a document to text
either programmatically, or with a simple keystroke?

Any suggestions will be greatly appreciated.

Thanks
 
D

Dave Lett

Hi JE,

If you simply want to pull the text of all the frame out of the current
document and place them into another document, then you can use the
following:

Dim iFrm As Integer
Dim oRngFrm As Range
Dim oRngInsert As Range
Dim oDocFrame As Document
Dim oDoc As Document

Set oDocFrame = ActiveDocument
Set oDoc = Documents.Add
Set oRngInsert = oDoc.Range
oRngInsert.Collapse Direction:=wdCollapseEnd
For iFrm = 1 To oDocFrame.Frames.Count
Set oRngFrm = oDocFrame.Frames(iFrm).Range
oRngInsert.FormattedText = oRngFrm.FormattedText
oRngInsert.InsertAfter Text:=vbCrLf
oRngInsert.Collapse Direction:=wdCollapseEnd
Next iFrm

If you want to remove the frames in the current document but keep the
contents of the frame in the current document, then you can use the
following. This routine deletes the frame and places the contents of the
frame BEFORE the paragraph that it's anchored to. If you want it to appear
after the paragraph that it's anchored to, then we can do that, too, but
it'll take a different routine.

Dim iFrm As Integer
Dim oRngFrm As Range
Dim oDocFrame As Document

Set oDocFrame = ActiveDocument

For iFrm = oDocFrame.Frames.Count To 1 Step -1
With oDocFrame.Frames(iFrm)
'''remove the borders
.Borders.Enable = False
.Delete
End With
Next iFrm

HTH,
Dave
 
J

je7383

Worked Great!

Thanks a lot!

J
--
JE


Dave Lett said:
Hi JE,

If you simply want to pull the text of all the frame out of the current
document and place them into another document, then you can use the
following:

Dim iFrm As Integer
Dim oRngFrm As Range
Dim oRngInsert As Range
Dim oDocFrame As Document
Dim oDoc As Document

Set oDocFrame = ActiveDocument
Set oDoc = Documents.Add
Set oRngInsert = oDoc.Range
oRngInsert.Collapse Direction:=wdCollapseEnd
For iFrm = 1 To oDocFrame.Frames.Count
Set oRngFrm = oDocFrame.Frames(iFrm).Range
oRngInsert.FormattedText = oRngFrm.FormattedText
oRngInsert.InsertAfter Text:=vbCrLf
oRngInsert.Collapse Direction:=wdCollapseEnd
Next iFrm

If you want to remove the frames in the current document but keep the
contents of the frame in the current document, then you can use the
following. This routine deletes the frame and places the contents of the
frame BEFORE the paragraph that it's anchored to. If you want it to appear
after the paragraph that it's anchored to, then we can do that, too, but
it'll take a different routine.

Dim iFrm As Integer
Dim oRngFrm As Range
Dim oDocFrame As Document

Set oDocFrame = ActiveDocument

For iFrm = oDocFrame.Frames.Count To 1 Step -1
With oDocFrame.Frames(iFrm)
'''remove the borders
.Borders.Enable = False
.Delete
End With
Next iFrm

HTH,
Dave
 

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