Lisa was telling us:
Lisa nous racontait que :
The example to delete all frames from Jean-Guy is looks better to me
(streamlined/efficient) than what I had posted. (Not surprising since
he knows what he's doing and I don't ;-)... His response wasn't
showing when I responded.)
The only "missing piece" is selecting the frames. (For some reason,
if you just delete a frame, it leaves behind the content of the frame
-- converting it to inline text (and inlineshapes, etc.). However, if
you select the frame then delete the selection, it removes the
content of the frame as well.)
So, with that addition, I think his code would be as shown below. (The
"Else: MsgBox" stuff is optional; you can remove that whole line if
you don't want to be told there that there are no frames if you try
to run the macro on a doc that doesn't include frames. Also, if you
have Option Explicit at the top of the module, you'd need to dim "i"
as integer)
Sub DeleteAllFrames()
With ActiveDocument
If .Frames.Count > 0 Then
For i = 1 To .Frames.Count
.Frames(1).Select
Selection.Delete
Next
Else: MsgBox "There are no frames in this document."
End If
End With
End Sub
I had not realized that the content of the frame had to go as well.
In that case, try this instead :
With ActiveDocument
Do While .Frames.Count > 0
.Frames(1).Range.Delete
Loop
End With
We need a loop because the first .Range.Delete deletes the content, but
leaves an empty frame on the page... So we need to delete each frame twice,
or use the "Select" tactic.
By the way, just as a side note, it is always better to avoid using the
Selection object whenever possible because it changes the user selection, it
is slower and unreliable. Also, while it is true that if you do not use
Option Explicit you do not have to declare all variables, I do not think it
is a good programming habit.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org