Problem starting a macro with application.caller and no object.

ChuckDrago

Active Member
Joined
Sep 7, 2007
Messages
470
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone,

I found a neat macro to simulate a button being depressed when using graphic elements acting as buttons, authored by Ryan Wells. (Simulate a Button Click with Rectangle Shape - wellsr.com). It uses 3D beveling and a timer to simulate the depression, very efficiently. In order to apply the effect, you must precede the code for the intended action by a call to Ryan's macro, because it uses an Application.Caller statement that needs to know to which graphic should the effect be applied.

And That is the root cause of the problem I am asking you to help on.

Once I completed the application of Ryan's code to a bunch of graphic pseudo-buttons in my app, I saved the work. From that point, every new instantiation of my work bombs out, error 2023 and message "The item with the specified name was not found".

Here are the beginning lines of Ryan's macro, with the offending line being indicated

<code/>Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SimulateButt*******()
Dim vTopType As Variant
Dim iTopInset As Integer
Dim iTopDepth As Integer

'Record original button properties
With ActiveSheet.Shapes(Application.Caller).ThreeD '<<< This is the error line
vTopType = .BevelTopType
iTopInset = .BevelTopInset
iTopDepth = .BevelTopDepth
End With
</code>

If I am not mistaken, the compiler fails to find an object (application.caller) active and errors out. The funny thing is that if you reset the error, then all graphic-buttons work as intended and without any problems.
How do I overcome this issue of error upon instantiation?
Thanks in advance.
Chuck
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi everyone,

I found a neat macro to simulate a button being depressed when using graphic elements acting as buttons, authored by Ryan Wells. (Simulate a Button Click with Rectangle Shape - wellsr.com). It uses 3D beveling and a timer to simulate the depression, very efficiently. In order to apply the effect, you must precede the code for the intended action by a call to Ryan's macro, because it uses an Application.Caller statement that needs to know to which graphic should the effect be applied.

And That is the root cause of the problem I am asking you to help on.

Once I completed the application of Ryan's code to a bunch of graphic pseudo-buttons in my app, I saved the work. From that point, every new instantiation of my work bombs out, error 2023 and message "The item with the specified name was not found".

Here are the beginning lines of Ryan's macro, with the offending line being indicated

<code>Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SimulateButt*******()
Dim vTopType As Variant
Dim iTopInset As Integer
Dim iTopDepth As Integer

'Record original button properties
With ActiveSheet.Shapes(Application.Caller).ThreeD '<<< This is the error line
vTopType = .BevelTopType
iTopInset = .BevelTopInset
iTopDepth = .BevelTopDepth
End With
</code>

If I am not mistaken, the compiler fails to find an object (application.caller) active and errors out. The funny thing is that if you reset the error, then all graphic-buttons work as intended and without any problems.
How do I overcome this issue of error upon instantiation?
Thanks in advance.
Chuck
Not sure I'm understanding what you mean by the bold text above, but you might try modifying the With-EndWith part to something like below and step through it using the F8 key to see if the second pass works.

Code:
Do
    On Error GoTo 0
    On Error Resume Next
    With ActiveSheet.Shapes(Application.Caller).ThreeD '<<< This is the error line
        vTopType = .BevelTopType
        iTopInset = .BevelTopInset
        iTopDepth = .BevelTopDepth
    End With
Loop While Err.Number <> 0
 
Upvote 0
JoeMo, BINGO!
Slight modification: I had to move to On Error GoTo 0 just above the Loop While line. Furthermore, the macro includes 3 sets of above code: 1) Recording the Button appearance, 2) Changing it to include the 3D effects and 3) Go back to the initial appearance (in effect, simulating a button depression). I had to apply the loop individually to each set, otherwise it looped without exiting. Just in closing: your suggestion acts on the code the way I explained before, that is, it avoids the initialization error condition (the error it's still there, but now it's skipped). Once the application is initialized, then clicking on a button generates an application.caller object and no further errors are produced. Thanks a lot, Joe!
 
Upvote 0
JoeMo, BINGO!
Slight modification: I had to move to On Error GoTo 0 just above the Loop While line. Furthermore, the macro includes 3 sets of above code: 1) Recording the Button appearance, 2) Changing it to include the 3D effects and 3) Go back to the initial appearance (in effect, simulating a button depression). I had to apply the loop individually to each set, otherwise it looped without exiting. Just in closing: your suggestion acts on the code the way I explained before, that is, it avoids the initialization error condition (the error it's still there, but now it's skipped). Once the application is initialized, then clicking on a button generates an application.caller object and no further errors are produced. Thanks a lot, Joe!
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,215,527
Messages
6,125,336
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top