Hidden UserForm apprears when hovering over Excel app - excel

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

Related

VBA opens Outlook from a Watch window

Recently I've stumbled upon a strange behaviour of VBA. In my Microsoft Excel Macro-Enabled Worksheet I have several sheets, with one named "Log". While I was debugging a code, I added a new watch with an expression Worksheets("Log"). When I click on the + box in front of it to expand the expression, Welcome to Outlook 2016 wizard pops up?!
On each subsequent click on the expression, New Profile window pops up.
Funny thing is, I don't even use Outlook and it alone cannot be uninstalled from the system and rest of the Office package. So, what is happening here and how can I prevent this strange behaviour?
I have it too, also when I have the watch set to a page of the worksheet.
It seems to happen when I forget to activate the sheet before I access it. After doing that the Macro and watch behave as expected.

Trying to ID a CommandButton on an Excel 2010 VBA application

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.

Macro button under customized ribbon tab tries to open old Excel file

I created a custom ribbon tab on my Excel like Excel_app_v1.xlsm, and a button under this ribbon tab is connected to a macro. So when I click this button, the macro does some table importing applications.
The first strange thing is that I created this ribbon tab and the button for only this Excel file, but the ribbon tab and the button appear in all other Excel files, even if the original Excel file Excel_app_v1.xlsm is not open.
The second problem is that I created a second version of my previous Excel file with "Save-as" option. So the new Excel file is like Excel_app_v2.xlsm. When I click the button under the ribbon tab, it opens the first Excel file Excel_app_v1.xlsm, even if it is not open. I deleted the first Excel file, but then I got an error like "Couldn't find the Excel_app_v1.xlsm on the path".
So obviously the macro button under the customized ribbon tab is linked to the first Excel file, but I couldn't find the menu option to change this. I added ThisWorkbook before all the sheet expressions in the vba code, but it didn't solve the problem. The button-click is still trying to open the old excel file.
The VBA code is below. The button is linked to the Sub ImportTable. Firstly it asks the user if the user wants to continue with the process. It opens the previous Excel file right after clicking on the button, at the same time as the Message Box appears.
Sub ImportTable()
Application.ScreenUpdating = False
YearMonth = ThisWorkbook.Sheets("tab1").Cells(11, 2).Value
' The Macro button opens the previous Excel file before clicking Yes or No on the message box
answer = MsgBox("Warning! Brings the newest source file. You want to continue?", vbYesNo + vbQuestion, "")
If answer = vbYes Then
RunSASCodeViaBatFile ' Another Sub which runs bat file to run a SAS-code. But it doesn't matter. Because the problem happens before I click on Yes or No.
InsertSASFileIntoExcel
Else ' Nothing happens if clicking No on the Message Box
End If
End Sub
The clue to fixing this quickly was posted below by roncruiser, with one slight twist.
Everyone on the web seems to feel that PERSONAL.XLSB is the key here — nope. In fact, playing with that file only confounded me for even longer. Here's what I did instead:
Right click the Ribbon and select Customize The Ribbon;
Navigate to the offending macros that you've installed with buttons;
Find and click on Import/Export;
Export your custom buttons (the macros will go right along just fine);
Open that resulting file, and edit out the offending references to the other file that's causing you so much grief — example:
<mso:button idQ="x1:HideRows_0_EA10D6" label="HideRows" imageMso="_3DPerspectiveDecrease" onAction="!HideRows" visible="true"/>
I took out everything after idQ-"x1... up to the actual name of the macro. I also took out the same external reference found in onAction="... Take everything up to the bang mark.
Save this under whatever name you wish, but with the same extension (for my setup, it was called ExportedCustomizations.exportedUI (yes, that long an extension));
Repeat the first few steps here, but this time import your edited file.
Voila, all is golden.
No messing around with wiping out existing work and starting all over. Worked a charm for me, so a big tip o' The Hat to roncruiser for the clue.
Just to confirm what sumgain have write above.
It works perfectly just do as he said : remove the part after the "x1:" that refers to a specific workbook until the begining of the maccro's name.
example :
When you export your custom ribbon with the maccro attached to it it will be write like below :
idQ="x1:C:_FolderName_Filename.xlsm_Fill_Formulas_Cells"
THen you remove the part mentionned and it will become like that :
idQ="x1:Fill_Formulas_Cells"
Same for onAction keep only the Maccro Name
Then it will works perfectly as long as you the maccro's name in the workbook stay consistent if you modified the Macros name then you have to modified it in the exportedUI file.
Then when you will reload the new file you can check in the Excel Options customize ribbon on the customize button if you put the pointer on you will see "Maccro: Name of your maccro"
And not the path of the file the maccro was from.
No need to use custom UI editor or any other things such as personnal maccro at least for that and if you are not bother to have custom ribbon in all of your woorkbook.
As well it is obvious but still good to remind it, you need to have the maccro in the workbook this procedure is just there to call the maccro that are associate to the workbook, it doesn't contain the code of the maccro.
Cheers
Romain
Does this still work? I have done this in the past with success but can't seem to get it to work now.
I export the file, edit it and import it back in.
it appears to work, but when i close the Ribbon options pane, my custom buttons disappear.
Same exact thing happened to me. There's a way to get around this.
By default, when you create a macro in Excel and run that macro through a custom ribbon button, that ribbon button macro works only in the workbook that contains it.
To get around this and have the button macros work in all workbooks, you'll need to create a Personal Macro Workbook. Then any macros that you store in your personal workbook on a computer become available to you in any workbook whenever you start Excel on that same computer.
Create a Personal Macro Workbook
To get the same ribbon button macros to work on another computer, you'll need to copy the Personal Macro Workbook to another computer and store it in the XLSTART folder. The link above has all the information you'll need.
Note: Delete the old ribbon button macros. Make sure you create new ribbon button macros that reference the macros from your Personal Macro Workbook.

Most User Friendly Way to use a VBA EXCEL Userform?

So I have programmed several userform with several user inputs(text boxes, check boxes, etc.) Now how can I use them outside of excel?
Currently I have to:
Open up the spreadsheet
Enable macros
Go to Developer Tab, View Code
Then find the right userform and run it or type F5.
Is there a more user-friendly way to run the userform? Its for testers who don't know vba or excel programming.
Thanks!
Yes, absolutely. You could create a button named after the form in question, and to that button assign the following macro:
Sub btn1()
frm1.Show
End sub
That's it! Of course, change the names according to what you have :)
I also reccomend having a button to close the form on the form itself.
OF COURSE this still uses Excel. If you want to use them on their own you could have something like this guy did: How to Open only UserForm of an excel macro from batch file

How to add user form as an icon/button to ribbon and show userform but still able to work with Excel File?

When I user the user form, I have to:
1) Alt + F11
2) Choose the Form
3) Run
4) Close the Form
5) Go back to Excel
Excel will not allow me to do anything if the form is not closed. Is there anyway to let me put a little icon on ribbon? And keep the user form appear while I am working with Excel?
You've got two parts to your question:
Adding an icon to the ribbon: Do you want the macro to be available for all spreadsheets?
If so, follow this guide to save your macro as an Excel Add-in, and then attach it to the ribbon.
If you only need it in the current spreadsheet, you could simplify things by adding a button to the spreadsheet which activates the macro (use this guide), or you could use a shortcut key to invoke the macro directly (use this guide, Assigning a shortcut to an existing macro section)
Keeping the dialog open: One of the properties of the UserForm is ShowModal; you can simply set that to false. Alternatively, as per the other answer, you can open it with MyForm.Show vbModeless.
Note that the properties of the form also allow you to provide a specific screen position too, so that the form isn't in the way while you're working: change StartUpPosition to 0 - Manual, and provide a value for Top and Left.
You don't need to do that :) You can simply launch the form in modeless mode to keep it open and work with the Excel file at the same time
Try this to launch the userform.
Sub Sample()
Userform1.Show vbModeless
End Sub
I think you should have to create another module and call the userform in that module. After that just put that macro on the ribbon.It may help you.....

Resources