【问题标题】:Open and close a shape with the same "button"使用相同的“按钮”打开和关闭形状
【发布时间】:2016-12-08 13:52:38
【问题描述】:

我有一个箭头,当我点击它时,应该会出现一个云形状。这现在工作正常。我现在想要的是,如果我再次单击相同的按钮,云应该会消失。我想我需要让我的云成为一个对象,以及它的状态或其他东西,但我还没有弄清楚如何......这是我的代码:

子气泡()

    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

结束子

【问题讨论】:

    标签: excel macros


    【解决方案1】:

    考虑:

    将 shp 调暗为字符串

    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
    

    改为。

    【讨论】:

    • 如果我这样做,我的工作表会变空:D
    • @z 在一张干净的床单上重复此操作。
    • @zooky 查看我的EDIT#1
    • 在这里给我一个错误:使用 ActiveSheet.Shapes("zooky")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 2021-09-03
    • 1970-01-01
    • 2011-02-22
    • 2019-01-19
    • 1970-01-01
    相关资源
    最近更新 更多