"VBA's Word App" is the eighth set of tutorials for me. The tutorial is specifically explained the application of VBA in Word, which is explained around "object -oriented programming". Then let everyone feel the beauty of Word VBA through examples.

2025/01/3022:28:36 technology 1543

[ sharing results, Sui Xizhen energy] God does not give you difficulties, how do you see through people's hearts; God does not give you failure, how do you find that the people around you are true or false; How to reflect on the self -introspection; God does not give you a gentleman and a villain in your life, how do you know how to improve the IQ! Essence

《VBA之Word应用》,是我推出第八套教程,教程是专门讲解VBA在Word中的应用,围绕“面向对象编程”讲解,首先让大家认识Word中VBA的对象,以及对象的属性、 Methods and then let everyone feel the beauty of Word VBA. This set of tutorials has a total of three books and 16 chapters. Today's content is Chapter 9: Section 4 of Shapes objects and Shape objects: VBA adds graphics in the document and fills color

Section 4 The Properties (1)

everyone, good In this section of the attribute explanation of the Shape object, the Shape object represents the objects in the drawing layer, such as self -selected graphics, any polygon, OLE object, ACTIVEX control or picture. The Shape object is a member of the Shapes collection, including all parts of the document or all the shapes of the document and all the shapes in the foot.

has three representative shapes:

1) Shapes collection, which represents all the shapes in the document;

2) shaperance object, indicating the designated subset of the shape in the document. For example, the Shaperange object can represent the first and fourth shapes in the document, and it can also represent all the selected shapes in the document;

3) Shape object, which represents the single shape in the document.

If you need to handle several shapes at the same time, or process multiple shapes in the selected area, use Shaperange collection.

will explain the AutoShapeType attributes of Shape objects, CANVASItems attributes, and file attributes.

1 Shape.autoshapetype property

This property returns or sets the graphical type of the specified Shape object. This object does not represent the lines or any polygon, but the selected graphics. Msoautoshapetype type (this enumeration value is introduced in Section 2)

syntax: Expression.autoshapetype

is required, which represents a variable of a shape object .

  • to change a When the shape type, this shape retains its size, color and other property.

2 shape.canvasitems property

This attribute returns a Canvasshapes object, which represents the collection of the shape on the shape of the canvas.

syntax: Expression.canvasItems

, Expression is necessary, representing a variable of a Shape object.

3 Shape.fill Properties

This property returns a Fillformat object, which contains a specified fill format attribute. This is only read.

syntax: Expression.fill

, Expression is necessary, representing a variable of a Shape object .

4 instance: adding and color filling

. We show you an instance in this example. Create a new in China The drawing canvas are added to it, and a circle and 16 -horned star type is added. Then add a rectangle to MyDocument, and then set the gradient type of prospect, background color and rectangular filling for it. Finally, all 16 corner stars in the activity document are replaced with a 32 -horned star. 'Create a new drawing canvas in the activity document, and add a circle and 16 star type to it.

DIM MYCANVAS AS Shape

Set Mycanvas = Activedocument.Shapes.addcanvas (Left: = 100, TOP: = 75, Width: = 150, Height: = 400)

Mycanvas.canvasitems.addshape Type: = msoshapeoval, TOP: = 25, left: = 25, width: = 150, height: = 150

mycanvas.canvasitems.addshape type: = moshape16pointstar, TOP: = 200, left: = 250, height: = 150 150

'Add a rectangle to MyDocument, and then set it for it Prospects, background color and gradient types filled.

With Activedocument.shapes.addshape (Msoshaperectangle, 280, 100, 150, 150) .fill

.Forecolor.RGB = RGB (128, 0, 0)

.B acstcolor.rgb = RGB (170, 170, 170)

.twocolorGradient MSOGRADIENTHONTAL , 1

END With

ACTIVEDOCUMENT.Shapes.addshape Msoshape16pointstar, 280, 280, 150

'replaced all 16 pounds in the activity document into 32 pound star

DIM MyDoc as Document

DIM MySHP As Shape

SET MyDoc = Activedocumntml5

For Each MySHP in ml0if myshp .Autoshapetype = msoshape16pointstar thene

Myshp.autoshapety = msoshape32pointstar

nd 5

END SUB

code Screenshot:

Code Explanation: (Summary) The operation effect of

code:

Back to:

Word's Autoshapetype attribute, Canvasitems attribute, and Fill attribute What? How does

use VBA to add graphics and color filling in the current document?

This content Reference program file: DOC 009 document .docm

my VBA practice experience for more than 20 years, all concentrated in each tutorial and application tools below: htmmmmmm L5

It is fair. Some people make you cry, and someone will make you laugh. Essence

technology Category Latest News