Frames
Frame Object
Represents a frame. The Frame object is a member of the Frames collection.
Frames Collection
The Frames collection includes all frames in a selection, range, or document.
Use Frames(index), where index is the index number, to return a single Frame object.
The index number represents the position of the frame in the selection, range, or document.
The following example allows text to wrap around the first frame in the active document.
ActiveDocument.Frames(1).TextWrap = True
Creating Frames
Use the Add method to add a frame around a range.
The following example adds a frame around the first paragraph in the active document.
ActiveDocument.Frames.Add Range:=ActiveDocument.Paragraphs(1).Range
If you want the frame to "move with text" then the relative vertical position must be paragraph
With ActiveDocument.Frames(1)
.RelativeVerticalPosition = wdRelativeVerticalPosition.wdRelativeVerticalPositionParagraph
End With
Tables in the Frames collection
If you have a table in your document which has been positioned in a particular place on the page then this table will appear in the Frames collection
The text wrapping for this table will be "Around"
Text Wrapping
You can wrap text around Shape or ShapeRange objects by using the WrapFormat property.
You can position a Shape or ShapeRange object by using the Top and Left properties.
Sub FramePositioning()
Dim objframe As Word.Frame
Set objframe = ActiveDocument.Frames.Item(1)
'there is no .Left
Debug.Print objframe.Height
Debug.Print objframe.HeightRule
Debug.Print objframe.Borders
Debug.Print objframe.HorizontalDistanceFromText
Debug.Print objframe.HorizontalPosition
Debug.Print objframe.LockAnchor
Debug.Print objframe.RelativeHorizontalPosition
Debug.Print objframe.RelativeVerticalPosition
Debug.Print objframe.Shading
Debug.Print objframe.TextWrap
Debug.Print objframe.VerticalDistanceFromText
Debug.Print objframe.VerticalPosition
Debug.Print objframe.Width
Debug.Print objframe.WidthRule
End Sub
Cut the offending shapes out of the document and paste them back into the document with their anchors at a new location, immediately below the heading paragraph.
Public Sub MoveAnchors
Dim objShape As Shape
For Each objShape In ActiveDocument.Shapes
If Left(objShape.Anchor.Style,7) = "heading" Then
objShape.Select
Selection.Cut
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.Paste
End If
Next objShape
End Sub
If you work with Frames.
The TextRange property of the TextFrame object returns a range containing the text within the text frame.
Frame Property
Returns a Frame object that represents the frame formatting for the specified style or find-and-replace operation. Read-only.
This example creates a style with frame formatting and then applies the style to the first paragraph in the selection.
Dim styleNew As Style
Set styleNew = ActiveDocument.Styles _
.Add(Name:="frame", Type:=wdStyleTypeParagraph)
With styleNew.Frame
.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
.HeightRule = wdFrameAuto
.WidthRule = wdFrameAuto
.TextWrap = True
End With
Selection.Paragraphs(1).Range.Style = "frame"
This example finds the first frame with wrap around formatting. If such a frame is found, a message is displayed on the status bar.
With ActiveDocument.Content.Find
.Text = ""
.Frame.TextWrap = True
.Execute Forward:=True, Wrap:=wdFindContinue, Format:=True
If .Found = True Then StatusBar = "Frame was found"
.Parent.Select
End With
Selection.Frames(1).TextWrap = false
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrev