使用相同的"按钮打开和关闭形状"

时间:2016-12-08 13:52:38

标签: excel macros

我有一个箭头,当我点击它时,应该会出现一个云形状。这现在工作正常。我现在想要的是,如果我再次点击相同的按钮,云应该消失。我猜我需要让我的云成为一个对象,至于它的状态或者什么,但我还没弄明白怎么样......这是我的代码:

子气泡()

    ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 795, 8.25, 107.25, 41.25). _
        Select
    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

1 个答案:

答案 0 :(得分:0)

考虑:

<击>     Dim shp As String

Sub Bubble()

    ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 795, 8.25, 107.25, 41.25). _
        Select

    shp = Selection.Name
    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 FlipFlop()
    With ActiveSheet.Shapes(shp)
        .Visible = Not .Visible
    End With
End Sub

<击> 我们创建 标注,并为您的Bubble()代码添加一个小模块。我们将FlipFlop()代码分配给您的箭头形状。

每次单击箭头时,标注将在可见和不可见之间切换。

修改#1:

我找到了

the problem.  Remove the old code and use:

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

代替。