toggle button size modified via vba

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
I'm 99% you can't make a toggle button using code, so can you change the size and location of one via code?

I have a few on a sheet and they seem to have resized/relocated on their own when switch computers and it's quite annoying so I was just going to have code (if possible) to ensure they don't do that again.

Thanks!
 
Is this what you want.

Your correct there is not Right and Bottom

Code:
Private Sub CommandButton1_Click()
'Modified  6/1/2019  2:48:29 AM  EDT
With ActiveSheet.ToggleButton1
.Left = ActiveCell.Left
.Top = ActiveCell.Top
.Width = ActiveCell.Width
.Height = ActiveCell.Height
End With
End Sub
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Just curious:

How many buttons are we talking about?
Is this a problem with two or three or more.

Is there a standard location where you want them?

Like straight down a column Like Column(1)

And what are these Toggle Buttons being used for?
 
Upvote 0
excellent. Thank you again sir. That was perfect

Oh- to answer your question- I have 3 toggle buttons that are in oddball places, otherwise yes, about 18 toggle buttons in a single column and another 6 in another column.

they are coded to change some cell values and I have their captions set to change with some code I put together.
 
Last edited:
Upvote 0
Again glad I was able to help you.

Not sure how much you know about Vba but there are other ways to run code that does not require Buttons

If your interested you can let me know.

Like you can Double click on a cell to run a script

You can for example Double Click on Range("A1") to enter "Hello" into Range("G14"

Just Double Clicking on a cell can run any script.

Having a large number of buttons on a sheet can be a Pain.

But then some people like seeing Buttons on their sheet.
 
Upvote 0
certainly no expert but I can dabble.

So I have a massive workbook that, if I could only delete the excel menu and the cell input/formula box along the top, would look like it's own program running. I use a TON of userforms, have cell generating sheets, etc. All fairly automated and runs like a champ. There's a "Settings" sheet that has the toggle buttons for turning "on/off" features (turns on and off other macros that run in other sheets) and I have, among other things, some buttons that do other things. Another example: I have a button that generates an "Archives" folder in a locally-specified folder while a second button generates (on user demand) an "Archives" Folder on a network-specified address. then the report that is automatically created and printed daily also is automatically emailed to certain individuals (via toggle button on/off). Anyway, the list goes on but it's a massive file. Now if I could only learn how to hide the whole excel menu and such so it was just a sheet.....it would look awesome!


Thanks
 
Upvote 0
If you want to hide the Formula Bar and the ribbon:
Try this:

Code:
Application.DisplayFormulaBar = False
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)"
 
Upvote 0
Wow:
Sounds like you know Vba very well. A great amount of code needed to do a project this big.

Glad to see you know Excel very well.
 
Upvote 0
You said I have a Ton of UserForms.

Have you ever used a UserForm Multipage?

It's like having 10 UserForms on the same UserForm

Just like have 10 sheets on the same Workbook.
 
Upvote 0
You said I have a Ton of UserForms.

Have you ever used a UserForm Multipage?

It's like having 10 UserForms on the same UserForm

Just like have 10 sheets on the same Workbook.


Oooh I'll have to play with that bit of ribbon code. I haven't heard of that before! I'm excited.

As for a userform multipage, no I haven't I'd be interested to learn more- My way is probably not at all the most efficient because I'm using "Next" and "Previous" buttons which are just buttons with Userform#.Show and Unload me....ya know.

I was surprised- i had a function kick an error today when I opened up another workbook- first time that's happened. And then when I removed the "On Error Goto" piece it didn't do it anymore...never seen that before.
 
Upvote 0
If you want to hide the Formula Bar and the ribbon:
Try this:

Code:
Application.DisplayFormulaBar = False
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)"

I like I like!

Is there a way to specify the window size (I want to make sure the user always sees each sheet to the max (versus scrolling left/right) and yes, the sheet isn't so large that on a lower res monitor it wouldn't work).

Also- this is awesome! Thank you.

Side note- Is it possible to make it so that it ONLY happens to this workbook (if i had another workbook open it isn't the same on that one)?

Thank you again!
 
Upvote 0

Forum statistics

Threads
1,224,750
Messages
6,180,740
Members
452,996
Latest member
nelsonsix66

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