Remove Undesired Frames in Your Word Document

https://www.datanumen.com/blogs/4-fast-methods-remove-undesired-frames-word-document/

Macro to remove all frames selected:

Sub RemoveAllFramesInSelection()
Dim objFrame As frame
Dim nFrame As Long

Application.ScreenUpdating = False

nFrame = Selection.Frames.Count

For Each objFrame In Selection.Frames
objFrame.Delete
Next objFrame
MsgBox (“All ” & nFrame & ” frames in this selection have been removed!”)

Application.ScreenUpdating = True
End Sub

Macro to remove All Frames in Current Document:

Sub RemoveAllFramesInDoc()
Dim objFrame As frame
Dim nFrame As Long

Application.ScreenUpdating = False

nFrame = ActiveDocument.Frames.Count

For Each objFrame In ActiveDocument.Frames
objFrame.Delete
Next objFrame
MsgBox (“All ” & nFrame & ” frames in this document have been removed!”)

Application.ScreenUpdating = True
End Sub

Macro to remove All Frames in Multiple Documents from a Folder:

Sub RemoveAllFramesInAllDocsInFolder()
Dim objDoc As Document
Dim dlgFile As FileDialog
Dim nFile As Integer
Dim objFrame As frame
Dim nFrame As Long

Set dlgFile = Application.FileDialog(msoFileDialogFilePicker)

With dlgFile
dlgFile.AllowMultiSelect = True
If .Show = -1 Then
For nFile = 1 To dlgFile.SelectedItems.Count
Documents.Open dlgFile.SelectedItems(nFile)
Set objDoc = ActiveDocument

nFrame = ActiveDocument.Frames.Count
For Each objFrame In ActiveDocument.Frames
objFrame.Delete
Next objFrame
objDoc.Save
objDoc.Close
Next nFile
Else
MsgBox “No file is selected! Please select a target file.”
Exit Sub
End If
End With
End Sub

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s