Execute a button from third party com add-In

abc_xyz

New Member
Joined
Jan 12, 2022
Messages
47
Office Version
  1. 2016
Platform
  1. Windows
I have installed a third party com add-in. It is a .vsto file format. The add-in has a Refresh All button. I want to execute that using VBA.
Is this even possible?
 
I could not set the isEnabled property to true, even though there is a property in the class to allow it, can that be done?
VBA Code:
Function ActivateRibbonItem(ByVal sItem As String) As Boolean
    Dim oParent As C_AccEx, oChild As IAccElement
  
    Set oParent = New C_AccEx
    Call oParent.GetAccessibleChildrenFromHwnd(Application.hwnd, TreeScope_Subtree)
    If oParent.ElementsCount Then
        For Each oChild In oParent.Items
            With oChild
                If LCase(.Name) = LCase(sItem) Then
                    If .IsEnabled = False Then .IsEnabled = True
                    .DoDefaultAction
                    ActivateRibbonItem = True
                End If
            End With
        Next oChild
    End If
'    Stop
End Function

It returns an error that says it's a read-only property.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
@561414
I see that it does not work on disabled buttons, can this method enable the button before clicking on it?
No. It won't work for enabling ribbon items that are currently disabled.

UI Ribbon items\menus\controls are contextual by definition meaning they appear\become activated on demand according to relevant actions so, it wouldn't make any sense to enable a control outside its appropriate task context. One example is the Paste button located in the ribbon Home Tab . The Paste button is only enabled when there is data in the clipboard. It should stay disabled for as long as the clipboard is empty. It would make no sense to enable it when there is nothing to be pasted to start with.

So, no. You can't enable a disabled button via the IsEnabled Property.

What does this mean? It means that the code has a serious flaw in design which I failed to notice. The IsEnabled Property should be ReadOnly . In fact , this defect applies to other Properties as well, such as ClassName, IsOffScreen, ItemType, ProcessID, IsPassword, ... etc . It makes no sense to edit\write any of those Properties.

I thank you for bringing this design flaw to my attention. I will revise the code later and see how I can fix this issue.
 
Upvote 0
@561414

Taking a second closer look at the code, there is actually no design flaw in it. The IsEnabled Property is in fact already ReadOnly so the user of the code can't write\edit that Property. Same applies to the other Properties I mentioned in my previous post.

The whole purpose of having the IAccElement interface was to make those Properties ReadOnly. That's why it is called *Interface* :)

I have such bad memory, I forget my own code after a weekend !
 
Last edited:
Upvote 0
I opted for the first method as I was getting some error with the second approach. Below is the final sub procedure which I want to make it perfect. However, ended up with more errors on line:

Any idea on how do I make it work on other workbooks?

VBA Code:
If Element.accRole(CHILDID_SELF) = RoleWanted _
    And Element.accName(CHILDID_SELF) = NameWanted Then
@abc_xyz

I too get the same error with that code. I am afraid, I won't have time to debug it.

You say you were getting some error with the second (Class) approach but you didn't say which error and where in the code the error is happening.

As I said, earlier in post#16, using the C_AccEx Class is much easier, doesn't require adding any external library references and shouldn't raise any errors.

I explained in post#18, the steps you will need to follow to use the Class and then it is just a simple case of calling the ActivateRibbonItem function.
 
Last edited:
Upvote 0
@abc_xyz

I too get the same error with that code. I am afraid, I won't have time to debug it.

You say you were getting some error with the second (Class) approach but you didn't say which error and where in the code the error is happening.

As I said, earlier in post#16, using the C_AccEx Class is much easier, doesn't require adding any external library references and shouldn't raise any errors.

I explained in post#18, the steps you will need to follow to use the Class and then it is just a simple case of calling the ActivateRibbonItem function.
With the second approach, I was able to make it work. However, it was very slow and caused my Excel application to crash (tried on other system and the results were the same). Would really appreciate if you could help me debug the first approach or guide me on how to do that.
 
Upvote 0
With the second approach, I was able to make it work. However, it was very slow and caused my Excel application to crash (tried on other system and the results were the same). Would really appreciate if you could help me debug the first approach or guide me on how to do that.
That's probably caused by a timing issue. I think the opened workbooks should be fully loaded before trying to click on the addin ribbon button.
Try introducing a small delay before calling the ActivateRibbonTab routine.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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