Excel Command bar controls

spacebouncer

Board Regular
Joined
Feb 7, 2014
Messages
109
When sheet is activated, I want to turn on Snap to Grid.

I've found the following code online to toggle the option, just like clicking the button, but it would be a whole lot better if anyone knows how to turn it on/off rather than just toggle.

Application.CommandBars.FindControl(ID:=549).Execute
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
spacebouncer,

Perhaps try....

Code:
Application.CommandBars.FindControl(ID:=549).Enabled = False

'and
Application.CommandBars.FindControl(ID:=549).Enabled = True

'or toggle enabled or not with
Application.CommandBars.FindControl(ID:=549).Enabled = Not Application.CommandBars.FindControl(ID:=549).Enabled

Hope that helps.
 
Upvote 0
No Idea what snap to grid is :)
But how about the below, that is:

When sheet is activated, I want to turn on Snap to Grid.

is what you want?


Code:
Private Sub Worksheet_Activate()
Application.CommandBars.FindControl(ID:=549).Execute
End Sub

Just create that sub for the Worksheet in question
 
Upvote 0
Hi Arithos,

Thanks for the reply. I had this, only problem is that it toggles on to off, or off to on. I'm looking to turn on regardless of whether its on or off.
 
Upvote 0
What about...

Rich (BB code):
Private Sub WorkBook_Activate()
Application.CommandBars.FindControl(ID:=549).Execute
Application.CommandBars.FindControl(ID:=549).Enabled = False
End Sub



 
Upvote 0
Thanks again for the reply Snakehips.

Just done a little reading -
CommandBarControl methods (Microsoft.Office.Core)
and
CommandBarControl.Enabled property (Microsoft.Office.Core)

Not sure if I'm reading this properly, but is this saying that the "enabled" property can only be read?

It seems the enabled property doesn't actually have any effect! I've set it to true and false and it doesn't influence shapes snapping. But hopefully have a solution....

Code:
[COLOR=#333333]
Private Sub WorkBook_Activate()[/COLOR][COLOR=#333333]
Application.CommandBars.FindControl(ID:=549).Reset[/COLOR]
Application.CommandBars.FindControl(ID:=549).Execute


Still another problem for you though! I was hoping Snap would allow me to position a shape either on gridlines or exactly in the middle, but it seems to put them in odd places around the middle.

My plan was to create .addshape, with size equal to gridlines, allowing me to position everything very nicely, but it doesn't work! Your ideas would be appreciated!
 
Upvote 0
Just seen the snap to shape... whoa! How have I managed to entirely miss this the whole time I've been using office!

Still, if you know whether there is any way I could snap to gridlines or mid-gridlines precisely, and no funny bits in between, that would be great! Cheers
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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