简体   繁体   English

检查OnAction是否为空

[英]Check if OnAction is empty

In this link , i use SHP.OnAction (where Dim SHP As Shape ) to print the name of the macro which is assigned to a shape. 在此链接中 ,我使用SHP.OnAction (其中Dim SHP As Shape )打印分配给形状的宏的名称。

Now I would like to check if SHP.OnAction is empty, which means there is no macro assigned to this object. 现在,我想检查SHP.OnAction是否为空,这意味着没有宏分配给该对象。 SHP.OnAction = "" does not work, it always return false . SHP.OnAction = ""不起作用,它总是返回false I have tried also ``SHP.OnAction = Empty , SHP.OnAction = Null , they always return false` too... 我也尝试过``SHP.OnAction = Empty , SHP.OnAction = Null , they always return false`。

Could anyone tell me how to verify if it is empty? 谁能告诉我如何验证它是否为空?

Edit1: I use the following piece of code, to go through all the shapes in a workbook, and check if there is a shape to that a macro is assigned. Edit1:我使用下面的代码,遍历工作簿中的所有形状,并检查是否存在分配了宏的形状。 I test it with some workbooks containing Chart or Picture , it seems that sShpaes.OnAction <> "" returns always true , even though the shape has no macro... 我用一些包含ChartPicture工作簿进行了测试,即使形状没有宏,似乎sShpaes.OnAction <> ""始终返回true

On Error Resume Next
Dim sShapes As Shape
existsAssignedShape = False

For Each ws In Worksheets
    For Each sShapes In ws.Shapes
        st = ws.Name & "     " & sShapes.Name & "     " & sShapes.OnAction
        Print #1, st
        Print #1, ""
        If (Not existsAssignedShape) And (sShpaes.OnAction <> "") Then
            existsAssignedShape = True
        End If
    Next sShapes
Next ws

If no macro has been assigned to an AutoShape, then the following will indicate True : 如果尚未将宏分配给自选图形,则以下内容将指示True

Sub hgfd()
    Dim s As Shape, t As String
    Set s = ActiveSheet.Shapes(1)
    t = CStr(s.OnAction)
    MsgBox t = ""
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM