为什么我在Excel中得到这个错误?

Sub Bubble2() ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 795, 8.25, 107.25, 41.25). _ Select Selection.Name = "zooky" Selection.ShapeRange.Adjustments.Item(1) = -0.25029 Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "text.................." With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 10). _ ParagraphFormat .FirstLineIndent = 0 .Alignment = msoAlignLeft End With With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 10).Font .NameComplexScript = "+mn-cs" .NameFarEast = "+mn-ea" .Fill.Visible = msoTrue .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1 .Fill.ForeColor.TintAndShade = 0 .Fill.ForeColor.Brightness = 0 .Fill.Transparency = 0 .Fill.Solid .Size = 11 .Name = "+mn-lt" End With Range("P5").Select End Sub Sub FlipFlop2() With ActiveSheet.Shapes("zooky") .Visible = Not .Visible End With End Sub 

Excel告诉我,在这一行没有这个名称的元素:With ActiveSheet.Shapes(“zooky”)

我想要做的是,如果我点击我的元素Excel应绘制一个云的形状,当我再次单击该元素时,它应该再次删除相同的云

有任何想法吗?

最好避免使用SelectSelection ,而应该定义一个Shape Object并将其Set为您创build的Shape(参见下面的代码)。

 Option Explicit Public Shp As Shape Sub Bubble2() ' set object reference to new created Shape Set Shp = ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 795, 8.25, 107.25, 41.25) With Shp .Name = "zooky" .Adjustments.Item(1) = -0.25029 .TextFrame2.TextRange.Characters.Text = "text.................." End With With Shp.TextFrame2.TextRange.Characters(1, 10) With .ParagraphFormat .FirstLineIndent = 0 .Alignment = msoAlignLeft End With With .Font .NameComplexScript = "+mn-cs" .NameFarEast = "+mn-ea" .Fill.Visible = msoTrue .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1 .Fill.ForeColor.TintAndShade = 0 .Fill.ForeColor.Brightness = 0 .Fill.Transparency = 0 .Fill.Solid .Size = 11 .Name = "+mn-lt" End With End With Range("P5").Select ' just for testing 'Call FlipFlop2 End Sub Sub FlipFlop2() With Shp .Visible = Not .Visible End With End Sub