Disable bold button
Asked Answered
D

2

6

I want to disable "bold" toggle button in an Excel sheet.

How can I do it?

I have the following code but it's not working:

CommandBarControl test = excel1.Application.CommandBars["Formatting"].FindControl(Id:113,Recursive:true);
if (test.Enabled)
{
MessageBox.Show(test.Caption + " enabled");
test.Visible = false;
test.Enabled = false;
}

I think it's not working because from Office 2007 they are using Ribbon Controls.

Can anyone help how to get the control of a specific button? So that I can change it's properties, enable/disable it by default, etc.

Discrimination answered 26/11, 2012 at 12:45 Comment(1)
While I don't have an answer to your question, I'm thinking when you disable the button, a user can still CTRL+B to bold text. The VBA library does not have an event but the VSTO might (I've never used it) Something like formatComplete or cellFormat, even cellLeave to check the formatting and then change it from bold. Anything to isolate the bolding event. Maybe even create a custom event by extending the cell class’ text format accessor to raise a bolding event for you to use. (if that’s possible) in C#Alti
T
1

I'm afraid the answer is indeed that it isn't possible.

I've been looking at possibilities with class modules, because I thought that using a class, you could intercept the event that changes text to bold and then cancel that event. However, everything I could find was related to other events (value changes, calculation, workbook structure changes etc).

Even if it would work though, it would involve some serious coding and be error prone.

Maybe you're going at it the wrong way - what's the reason you remove this button? Probably there's another solution to your problem. And as mentioned before, removing the button doesn't block the possibility to use ctrl+B or to paste bold text - you simply can't prevent this.

Traveller answered 17/3, 2013 at 0:12 Comment(0)
D
0

Not the answer you want, I'm sure, but I'm afraid this cannot be done.

Determinative answered 30/11, 2012 at 1:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.