"VBA's Word Application" is the eighth set of tutorials I launched. The tutorial specifically explains the application of VBA in Word. It focuses on "object-oriented programming". First, let everyone understand the objects of VBA in Word, as well as the properties and methods of

2025/04/2100:06:38 technology 1478

[ Share the results, rejoice in positive energy] When the heart is happy, we do not see the pain hidden behind it. When the heart is peaceful, the ups and downs are on the way to come. Everything will not last or be eternal. This is impermanence. .

"VBA Word Application" (10178982) is the eighth set of tutorials I launched. The tutorial specifically explains the application of VBA in Word. It focuses on "object-oriented programming". First, let everyone understand the objects of VBA in Word, as well as the properties and methods of objects, and then let everyone feel the beauty of Word VBA through examples. This set of tutorials has three volumes and sixteen chapters. Today's content is Chapter 9, Section 6: VBA adds graphics and hides graphics in the document

Section 6 Properties of Shape Object (III)

Hello everyone, we will continue to explain the properties of Shape object in this section. In the previous lecture, we will explain the Name attributes, Shadow attributes and TextFrame attributes of Shape object. This section introduces the TextEffect attribute, Visible attribute and Type attribute of Shape object.

1 Shape.TextEffect attribute

This property returns a TextEffectFormat object, which contains the text effect formatting properties of the specified shape. This is a read-only property.

Syntax: expression.TextEffectt

where expression is necessary to represent a variable of a Shape object.

  • This property is suitable for Shape objects representing the word art.

2 Shape.Visible attribute

The object or application format specified by this attribute will return true if it is visible.

Syntax: expression.Visible

where expression is necessary to represent a variable of a Shape object.

3 Shape.Type attribute

This attribute returns the type of embedded graphics. Read-only MsoShapeType.

  • MsoShapeType is different from MsoAutoShapeType. You can carefully compare the enumeration values ​​of both. MsoAutoShapeType is one of the types of MsoShapeType

Syntax: expression.Type

where expression is necessary, representing a variable of a Shape object.

MsoShapeType Enumeration values:

1) mso3DModel 30 3d model

2) msoAutoShape 1 AutoShape

3) msoCallout 2 Label

4) msoCanvas 20 canvas

5) msoChart 3 Chart

6) msoComment 4 Annotation

7) msoContentApp 27 Content Office Add-in

8) msoDiagram 21 Planning

9) msoEmbeddedOLEObject 7 Embedded OLEObject

10) msoFormControl 8 Form Control

11) msoFreeform 5 Arbitrary polygon

12) msoGraphic 28 Graphic

13) msoGroup 6 Group

14) msoIgxGraphic 24 SmartArt Graphic

15) msoInk 22 Ink

16) msoInkComment 23 Ink comment

17) msoLine 9 Line

18) msoLinked3DModel 31 Linked 3D model

19) msoLinkedGraphic 29 Linked Graphic

20) msoLinkedOLEObject 10 Linked OLE Object

21) msoLinkedPicture 11 Linked picture

22) msoMedia 16 Media

23) msoOLEControlObject 12 OLE control object

24) msoPicture 13 Picture

25) msoPlaceholder 14 placeholder

26) msoScriptAnchor 18 script positioning mark.

27) msoShapeTypeMixed -2 ​​Mixed shape type

28) msoTable 19 Table

29) msoTextBox 17 Text box

30) msoTextEffect 15 Text effect

31) msoWebVideo 26 Web Video

4 Example: Add a graph and select hidden

In this example, we will add some content to the current document, first add a canvas, add a shape circle on the canvas; then add some shapes.

Finally, we use the Shape.Type attribute and the AutoShapeType attribute to judge to selectively hide the graphics.Let's look at the code:

Sub mynzE()

Set myDoc = ActiveDocument

'Add canvas in the current document

Set myCanvas = myDoc.Shapes.AddCanvas(Left:=10, Top:=20, Width:=150, Height:=400)

'Add shape in the canvas

myCanvas.CanvasItems.AddShape Type:=msoShapeOval, Top:=25, Left:=25, Width:=150, Height:=150

'Add several automatic graphics in the current document

With myDoc

.Shapes.AddShape msoShapeBalloon, 100, 70, 150, 60

.Shapes.AddShape msoShapeRectangle, 200, 80, 150, 60

.Shapes.AddShape msoShapeCan, 300, 90, 150, 60

End With

For Each myShp In myDoc.Shapes

'Hide rectangle

If myShp.AutoShapeType = msoShapeRectangle Then

'myShp.Visible = True

myShp.Visible = False

End If

'Hide canvas and the shape above

If myShp.Type = msoCanvas Then

'myShp.Visible = True

myShp.Visible = False

End If

Next

End Sub

Code screenshot:

Code interpretation: (omitted) The running effect of

code:

code:

We set a breakpoint in the middle of the code and conducted two tests, one is the screenshot before hiding, and the other is the screenshot after hiding:

Today's content dedication:

What is the meaning of the TextEffect attribute, Shadow attribute and Type attribute of the Shape object in Word?

How to use VBA to add graphics and text to the current document and set the shadow filling?

The content of this lecture reference program file: Doc 009 document.docm

My more than 20 years of VBA practical experience is condensed in the following tutorials and application tools:

[ Sharing the results, rejoicing with positive energy] Because life has decay, the concept of time has been created. If life is eternal, then time will no longer exist. .

technology Category Latest News