Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable bold button

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.

like image 681
user1853368 Avatar asked Nov 26 '12 12:11

user1853368


1 Answers

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.

like image 159
Joost Avatar answered Oct 17 '22 21:10

Joost