Shapes
Text Boxes
For adding textboxes refer to [Pages > VBA Code > Text Boxes]
Deleting Shapes
For some reason (msoPicture) objects can only be removed from headers and footers if the header and footer is activated.
This line of code will not work
objHeader.Range.ShapeRange.Item("picturename").Delete
Adding Shapes
ActiveDocument.Shapes.AddShape(Type:=msoAutoShapeType.msoShapeRectangle, _
Left:=10, _
Top:=10, _
Width:=10, _
Height:=10, _
Anchor:=False)
Anchor - Optional Variant. A Range object that represents the text to which the AutoShape is bound. If Anchor is specified, the anchor is positioned at the beginning of the first paragraph in the anchoring range. If this argument is omitted, the anchoring range is selected automatically and the AutoShape is positioned relative to the top and left edges of the page.
ActiveDocument.Shapes.AddCallout(Type:=msoCalloutType.msoCalloutOne, _
Left:=10, Top:=10, Width:=10, Height:=10, Anchor:=False)
ActiveDocument.Shapes.AddCanvas(Left:=10, Top:=10, Width:=10, Height:=10, Anchor:=False)
ActiveDocument.Shapes.AddCurve(SafeArrayOfPoints, Anchor)
ActiveDocument.Shapes.AddDiagram(Type:=msoDiagramType.msoDiagramOrgChart , _
Left:=10, Top:=10, Width:=10, Height:=10, Anchor:=False)
ActiveDocument.Shapes.AddLabel(Type:=msoTextOrientation.msoTextOrientationUpward , _
Left:=10, Top:=10, Width:=10, Height:=10, Anchor:=False)
ActiveDocument.Shapes.AddLine(BeginX:= , _
BeginY:= , _
EndX:= , _
EndY:= ,
Anchor:=False)
BeginX - Single. The horizontal position, measured in points, of the line's starting point, relative to the anchor.
BeginY - Single. The vertical position, measured in points, of the line's starting point, relative to the anchor.
EndX - Single. The horizontal position, measured in points, of the line's end point, relative to the anchor.
EndY - Single. The vertical position, measured in points, of the line's end point, relative to the anchor.
ActiveDocument.Shapes.AddPicture(FileName:= , _
LinkToFile:= , _
SaveWithDocument:= , _
Range:= )
FileName - String. The path and file name of the picture.
LinkToFile - Variant. True to link the picture to the file from which it was created. False to make the picture an independent copy of the file. The default value is False.
SaveWithDocument - Variant. True to save the linked picture with the document. The default value is False.
Range - Variant. The location where the picture will be placed in the text. If the range isn't collapsed, the picture replaces the range; otherwise, the picture is inserted. If this argument is omitted, the picture is placed automatically.
ActiveDocument.Shapes.AddPolyline(SafeArrayOfPoints, Anchor)
Changing the Type
Dim objShape As Shape
objShape.AutoShapeType = msoAutoShapeType.msoShapePentagon
Returning a Shape
Dim objShape As Word.Shape
Set objShape = ActiveDocument.Shapes.Range("shapename")
Set objShape = ActiveDocument.Shapes.Item("shapename")
Set objShape = ActiveDocument.Shapes.Range(1)
Set objShape = ActiveDocument.Shapes.Item(1)
It is often simpler to use Item when you just have a single item
Returning Several Shapes
You can use VBA.Array to construct a list
ActiveDocument.Shapes.Range(Array("shaperange1","shaperange2"))
Change the fill color of the first shape in the selection
Selection.ShapeRange(1).Fill.ForeColor.RGB = RGB(10,20,30)
objShape.TextFrame.HasText
This is not boolean but integer
objShape.TextFrame.TextRange.Fields.Locked
This is not boolean but integer
Sub ShapePositioning2()
Dim objshape As Word.Shape
Set objshape = ActiveDocument.Sections(1).Range.ShapeRange(1)
'this can be a textbox
Debug.Print objshape.Adjustments
Debug.Print objshape.AlternativeText
Debug.Print objshape.Anchor
Debug.Print objshape.AutoShapeType
Debug.Print objshape.Callout
Debug.Print objshape.CanvasItems
Debug.Print objshape.Child
Debug.Print objshape.Diagram
Debug.Print objshape.DiagramNode
Debug.Print objshape.Fill
Debug.Print objshape.GroupItems
Debug.Print objshape.HasDiagram
Debug.Print objshape.HasDiagramNode
Debug.Print objshape.Height
Debug.Print objshape.HorizontalFlip
Debug.Print objshape.Hyperlink
Debug.Print objshape.ID
Debug.Print objshape.LayoutInCell
Debug.Print objshape.Left
Debug.Print objshape.Line
Debug.Print objshape.LinkFormat
Debug.Print objshape.LockAnchor
Debug.Print objshape.LockAspectRatio
Debug.Print objshape.Nodes
Debug.Print objshape.OLEFormat
Debug.Print objshape.Parent
Debug.Print objshape.ParentGroup
Debug.Print objshape.PictureFormat
Debug.Print objshape.RelativeHorizontalPosition
Debug.Print objshape.RelativeVerticalPosition
Debug.Print objshape.Rotation
Debug.Print objshape.ScaleHeight
Debug.Print objshape.ScaleWidth
Debug.Print objshape.Shadow
Debug.Print objshape.TextEffect
Debug.Print objshape.TextFrame
Debug.Print objshape.ThreeD
Debug.Print objshape.Top
Debug.Print objshape.Type
Debug.Print objshape.VerticalFlip
Debug.Print objshape.Vertices
Debug.Print objshape.Width
Debug.Print objshape.WrapFormat
Debug.Print objshape.ZOrderPosition
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext