Trying to ID a CommandButton on an Excel 2010 VBA application - excel

I've just started a new contract and am working with Office VBA again after about 20 years. There is a spreadsheet I'm working on where command buttons disappear after the document saves. I've been reading other threads that suggest as a fix setting the size of the button after saving. However, I can't figure out how to identify that button in code.
When I click "Format", there is no place where the name of the object appears. There's a macro attached to it, but I see no way to identify the "sender" when the macro fires.
The macro pops up a form, and after the user enters some information and submits, it saves the sheet, and the button goes "poof".
Is there any way to get the name of the button in the macro so I can resize it?
Thanks!

If you right-click the button, its name appears in the upper left hand corner of the spreadsheet in the Developer ribbon, right below the "Visual Basic" and "Macros" menu items. In my case, it was "Button 1".
Accessing it was non-intuitive for a guy used to working with full-blown .NET apps, but the button is a "Shape". So, addressing the button is accomplished with the identifier ActiveSheet.Shapes("Button 1"). With this object, you can access its properties and methods.

Related

get button to appear no matter how far you scroll down excel sheet

In my excel document I want the button to appear no matter how far I scroll down. I don't know if there is a way to pin the button so that when I scroll down the button still appears. I dont want to scroll up all the way up to click the button. I added a photo if that makes things clearer.
I would suggest creating a custom tab on the ribbon with the macro you want to run. Unfortunately, there is not a way to pin a button in place, unless you use a userform per Tim Williams suggestion. I created a custom ribbon tab to get around this hassle.

Adding macro button to trigger a specific Macro

Whenever I add a custom Macro button to the Quick Access Toolbar , it is a generic Macro window invocation button. What I want is that if I click on the button, a specific Macro should directly start running. As of now there are 2-3 steps before I do that. First of all I click on the icon on the quick access toolbar , another small drop down shows up unnecessarily as shown here ( not sure why Add Ons is appearing here, I never added)
Secondly, if I click on the bigger Macros icon in the dropdown again , I get a dialog box where I have to choose macro from a list. I don't want to go through all this. As soon as I click on the button, a specific macro (I should be able to configure name of the macro) should start. I know there is a shortcut available for triggering a specific macro but I prefer a button.
If you don't want to configure QAT buttons manually you may consider developing a COM based add-in instead. See Walkthrough: Create your first VSTO Add-in for Outlook for more information.
To customize the ribbon UI you can use the designer provided by VSTO, see Walkthrough: Create a custom tab by using the Ribbon Designer.

Hidden UserForm apprears when hovering over Excel app

I'm developing a tool for my company using Excel VBA. In this tool I need UserForms. I noticed that when i hide them (usually when the user clicks "Ok", the code processes the info I need and there's a line somewhere saying Me.Hide), they still appear when I hover the mouse on the Excel app in the taskbar, when another app is on top.
The userform does disappear when I click on Excel.
I also noticed that the data the user entered is still there when I open the userform again. I don't know if these issues are related.
(The question is of course how to have the userform not appear and how to reset the fields)
I used Unload Me instead of Me.Hide and it worked perfectly

Second action button displaying in excel VBA, but I cannot select it

I'm new to using VB w/ excel, so please forgive my lack of technical verbiage.
I recently received a new laptop, and transfered an excel file from my old laptop with VB setup to automatically generate reports. On the new laptop, when I click on my Active X Command Buttons, a smaller duplicate button appears. For some of these buttons, I can double click and the needed action is performed if that second button is under my mouse icon. For others (see picture), this second button displays, but when I move my mouse to get to it, it disappears.
Any help in resolving this would be greatly appreciated.
Try to select one button and use 'Tab' Key to select next one

Excel 2007 Combo Box - Developer Ribbon vs. VBA Module

Could someone please explain to me the difference between the combo box that's available via the Developer Ribbon in Excel 2007 vs. the Combo Box control that's in the VBA editor? I cannot get this simple line of code to work using the Developer combo box:
MsgBox Combo1.Value
I've tied it to the change event and it seems to be syntactically correct (I'm not a VBA coder by any stretch).
Is the Developer Ribbon version some bastardized craptastic Microsoft shortcut?
What I'm trying to do is populate a second combo box based on the selection of the first combo box. I'd rather not build a case statement for every possible selection. Is this possible using the Developer ribbon version?
You are talking about the Insert button on the Developer tab correct? From that button you can add an ActiveX control or Form control. You're better off using the form controls if your new to programming as they will behave more in line with any Excel VBA reading you've done and the help file. With the Form controls you can right click and choose 'View Code' and/or 'Rename Control and Code'. Renaming the control allows you to address it in VBA however you like. e.g. - Combo1.value or myFavoriteCombo.value
That being said, to answer your question directly, be sure you know the controls full name. If you used a form control and it was the first one you put on the sheet it will be named ComboBox1. To get to the combobox's properties you have to walk through it's 'parent' sheet.
i.e.
MsgBox Sheet1.ComboBox1.value (using the sheet's code name)
or
MsgBox Worksheets("SheetName").ComboBox1.value (using the sheets name as it appears on the Excel tab)

Resources