Accessing built-in Ribbon control properties

Add-in Express™ Support Service
That's what is more important than anything else

Accessing built-in Ribbon control properties
 
Michiel




Posts: 11
Joined: 2021-10-25
Hello,

I would like to apply customized formatting on created tables. Word has several options to do this already without coding. However, one option I cannot set, which is the TableStyleTotalRowWord checkbox on the Tabe Formatting ribbon, which is set unchecked by default each time a table is inserted.
Only when checked, this checkbox applies the total row style on the bottom row.

I need this checkbox to be checked by default. So that each time I insert a table, the the last row style is applied. One way I can think of is to find a way to change the default values of the built-in ribbon control properties of MS Office. Specifically this TableStyleTotalRowWord checkbox. Can the Addin-express help me to get to these properties?

I have also looked into a different method, to set the value of the checkbox each time a table is inserted. However, I cannot get an event when a table is created (as this is not a button, but seems to be a special ribbon-control, which doesn't seem to be possible to catch with Add-in Express).
Also, the checkbox needs to be set after the event took place. Not before.
Setting the checkbox once on initialization seems also no solution as the checkbox is unchecked by Word automaticaly each time a new table is inserted. And also then, I cannot find how to change the checked/unchecked value.
I hope someone can help me with a solution.

Regards,
Michiel
Posted 25 Oct, 2021 10:22:57 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
Hello Michiel,

I'm not sure that I understand you completely. I've recorded a VBA macro while creating a table and setting a style. Obviously, that check box reflects the Table.ApplyStyleLastRow property of the selected table; see https://docs.microsoft.com/en-us/office/vba/api/word.table.applystylelastrow.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Oct, 2021 11:07:49 Top
Michiel




Posts: 11
Joined: 2021-10-25
Hello Andrei,

Thanks, yet this is indeed not exactly what I meant. I try to explain a little better.

I am not creating a table using code. There is this special click-drag table widget in the Word ribbon which you can use to create a table. I think it's very user friendly. Every time a user uses this however the ApplyStyleLastRow property is unchecked (false). I would like to have this property checked (true) at all times.

As I cannot catch a clickevent on this special widget I cannot intercept it.

So I was wondering perhaps there would be a way to set the default value of this property at the intialization of the addin? I would need access then however to the default values of the built-in controls of Word.

Regards,
Michiel

N.B. The poster if this thread addresses just about the same issue. However no solution is given there. And in my case I do apply custom formatting: https://answers.microsoft.com/en-us/msoffice/forum/all/change-the-default-boxes-being-checked-in-table/ef821529-1e36-453c-aeb4-9fc7861b12b5
Posted 26 Oct, 2021 02:52:22 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
Hello Michiel,

No such way exists.

You can try the following approach: detect creating a table via Insert | Table | {grid}, check the style and select the checkbox if required.

To detect creating a table using that Ribbon control, use TadxRibbonCommand components to intercept all interceptable Ribbon commands creating a new table. The remaining one would be the Insert table grid.

Now you need is to detect a new table added. To achieve this, handle the Commandbars.OnUpdate event - in Add-in Express it is mapped to the {Word Events component}.CommandbarUpdate event. In the event procedure, make sure the selection is a table and the number of tables in the Table.Parent object (consider adding a table within a table cell) changed - this requires that you get the number of tables on the previous CommandbarUpdate event. You'll also need to find out how to reset the number of tables stored. I suppose you can do this in the SelectionChange event. As to the CommandbarUpdate event, it is a heart-beat event: it occurs frequently and your event procedure should be effective to prevent slowing down the Word UI.

Once you detect a new table added, get WordApp.Commandbars, check whether WordApp.CommandBars.GetPressedMso('TableStyleTotalRowWord') returns false and invoke WordApp.CommandBars.ExecuteMso('TableStyleTotalRowWord') to select that control. Note however that you may need to make these calls after a small delay to let Word change its Ribbon controls before you check them. If this is the case, use a timer that works on the main thread.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Oct, 2021 04:46:18 Top
Michiel




Posts: 11
Joined: 2021-10-25
Hello Andrei,

Thanks for your proposed solution. I am trying it out, but I cannot find the CommandbarUpdate event on the TadxWordAppEvents component. Is this the correct component?

Regards,
Michiel
Posted 26 Oct, 2021 06:50:57 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
Ah, that was my fault. I'm sorry for it.

There's no CommandBarsUpdate event on that component. You can get Application.CommandBars and connect to the CommandBasr.OnUpdate event yourself. Here's that event on the object model reference page: https://docs.microsoft.com/en-us/office/vba/api/office.commandbars.onupdate

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Oct, 2021 09:13:41 Top