Embedding a form into a MultiPage tab in Excel VBA - excel

I am using Excel 2010. I have already created and tested 2 complex forms frmA and frmB. They run and then save data to the workbook when user hits Apply or OK. Now my user wants frmA to be able to call frmB, do some work, then return to frmA. I thought it might look professional if they could be on a MultiPage, but I don’t want to rebuild and retest these forms.
Is there anyway I can create a 2-tab MultiPage form and then make frmA appear on the first tab, frmB appear on the second? Then I can simply handle the communication between the two instead of recoding.
Or maybe I can just paste all the objects and code from each form onto the tabs and do some object renaming. The retesting will be extensive, though.
If not, I will have to do frmA.show, (user clicks Open frmB button), frmA.Hide, frmB.Initialize, frmB.Show, (do some work, hit Apply/OK/Cancel), (update spreadsheet with changes), frmB.Hide/Unload, (frmA.Initialize due to changes), frmA.Show. I have not gotten this to work properly yet – frmA disappears and doesn’t come back, but I will work on it if the MultiPage is not possible.
Maybe you can save me time by pointing me in the right direction.

I am accepting #guitarthrower 's answer:
To answer your question, no you cannot embed one userform in another using Excel VBA. – guitarthrower

Related

Allow "Mouse Click" event or "switch Excel tab" when a macro is running

I have a macro that extracts data from Microfocus RUMBA Mainframe Display and puts in Excel rows one after the other. I have created a Global Mainframe object and that is used for extraction to Excel. But when the process is running and if user decides to stop the processing he cannot click on Stop button on Excel or go to different tabs to see the data being pasted. He has to clicks like 6 times before tabs are switched or stopped.
I see that DoEvents allows mouse click events in the loop to do things but the code is written in a way that there is a lot of lines with in the loop and a function with no loop, and placing DoEvents after everyline seems irrational. I have a feeling there is a better to do that but not sure what that is. Can anyone please help?.
VBA is single threaded. So you can't have one VBA action interrupt another. If you had a cancel button, for example, and the user was allowed to click it via a DoEvents processing the cancel action would still run after the currently running procedure.
In Excel this single threaded nature ends up being a good thing because you generally don't want the user interacting with the workbook while you are making programmatic changes. If this was allowed you would get undefined behavior.
Your best course of action would be to make a .NET application that uses the Excel Interop extensions to move the data from the mainframe to Excel. If you use VB.NET then you will find the code is quite similar to VBA. In fact, the Excel.Application object model is identical so the macro code you already have ports cleanly over.
There is an add-in that will help RUMBA development here:
https://www.microfocus.com/documentation/rumba/desktop951/RumbaSystemAdminGuide/GUID-DDB7571D-6167-4F8B-876E-E7450F3030B2.html

Excel’s cursor/selection focus after inserting content add-ins

In Excel, I’m having my cursor/selection on a specific cell. Up until a recent Office update, the behavior upon inserting an Office.js-powered “content add-in” was like this:
The add-in is being inserted
The container of the web control is focused (you get the resize handles and Excel reveals the Drawing Tools menu) and the focus on the sheet is lost
getSelectedRange() right now would not yield any results but an error
You need to make at least one click into the web control’s area to de-focus the container and focus both the web control and re-focus the cursor/selection on the sheet
getSelectedRange() works now
After a recent update, I’m using Excel for Office 365 Version 16.0.11328.20362 now. And the behavior changed to this:
The add-in is being inserted — unchanged
The container of the web control is focused and the focus on the sheet is lost — unchanged
getSelectedRange() right now would not yield any results but an error — unchanged
Clicks on the web control don’t change the focus anymore, the container keeps being focused!
While the old behavior was already cumbersome as interaction between the add-in and the sheet was not possible directly after add-in insertion (only after at least one click), now not even the workaround of making that single click in the add-in is working anymore.
My original requirement was to read data from the sheet that has been selected just prior to inserting the add-in (just like it works with the native Excel charts). That’s why I had to come up with this one-click workaround in the first place.
What is now the best (if any) way to work with the workbook/sheet right after inserting the add-in with as few quirks as possible?

How to make .xlam add-in functionalities workbook specific?

Currently my office is using an excel my team created to manage a certain kind of orders. This file has quite a lot of functionalities that are controlled by some hotkeys and a couple of userforms. Every couple of months when we want to add some new functions or repair some bugs every user needs to download the updated file. (The old file becomes unusable when a new version is available.)
​
To make this file more user friendly and to make it easier for us to manage the current version and distributing the new one I started to convert this file to an .xlam add in. I was inspired by a post a couple weeks/month ago about add in distributing in an office setting.
​
The problem I'm facing now is that ones the add in is loaded the add-in setting are used for every open workbook.
How I want the add in to be used is as follows:
When excel is started the add in tab is visible in the ribbon with 1 button visible. When this button is pressed a couple of sheets are added to the workbook with the basic data that is needed. And all the other buttons are now visible and enabled.
​
The problem is that once that activation button is pressed all the other buttons are also visible and usable in every other workbook the user has open or opens.
​
So, my question is, is it possible to make the buttons of the custom ribbon (visible or not visible) workbook specific? And this way the functionalities of the add in only available when the activation button is pressed in that specific workbook. And lastly making the variables defined in the add in also workbook specific?
​
Is this all possible with an .xlam add in or do I need to start with VTSO?
​
It is possible to do this within the file. In your callback, you can use
Call RefreshRibbon(Tag:=""), which won't return any macro matches (by design) and therefore all will be disabled. This is a great resource with several examples.
https://www.rondebruin.nl/win/s2/win013.htm

How to Trigger/Initialise Excel VB User Forms Without Showing the Workbooks?

I have created an excel vba tool that utilises userforms to create a shopping experience for the user. Once the user opens the tool he will be able to pick orders from the user form. The code then processes the orders and returns with a calculated estimated cost.
The Problem is I don't want to let the workbook(and sheets in it) visible to the user. I need to hide my active workbook without any pop ups.
I recently crossed with the below solution however, I found out that upon initial launch by the user, he encountered "Security Warning Macros have been disabled. Enable Content (button)" which renders the initial solution worthless. Any advice is appreciated. TIA.
ActiveWorkbook.Windows(1).Visible = False
forgot to mention the obvious
XLAM
save your book as an xlam. put it in the addin folder (or explicitly point to it) and select it through Excel's interface.
addins are not visible by default
you still have to manage the security warning, frankly this is a user concern that you'll likely be forced to address and it's an issue that will never go away.
i will not say this is "good" advice and you may scof or reject the idea on principle, but if you don't have a legit way of signing your projects, consider the possibility of installing a personal cert on the users computer and signing the project locally or walking users through the process remotely
You can permanently enable macros for a certain workbook in the Trust Center of the excel workbook. So whenever the user opens the workbook, he/she will not need press the button each time to activate anything macro related.
In your case you want to select: Enable all macros (not recommended; potentially dangerous code can run)

Excel 2007-VBA, Right Click Buttons

I am having a strange Excel 2007 issue, and I am not quite sure how to explain this. So bear with me please....
I have created a few right click buttons to call various backend VBA functions that I have written. They were working fine earlier today, and now for some reason, a button is appearing that is not from the code in my worksheet. When you click it, it is attempting to open another worksheet and execute code from it. The two files are not in the same directory nor are they named anything similar. I deleted the file that the button is trying to execute from and now it just simply gives me an error 400.
So, I couldn’t figure that out, and have since deleted every single scrap of code in the backend of this file, and the button still appears. Any ideas what could be causing this? It seems like maybe its mixing files up or saving a copy somewhere in a temp directory and trying to access that instead of the actual code that is written in the VBA. Is there a cache I need to clear out or something?
I know I didn’t exactly do a great job describing this, so I will be more than happy to provide any and all other details that you may need. Just let me know what is going on.
EDIT #1 -- New Information ==
I can even open a new, completely blank excel file and the right click button is still there.
EDIT #2 -- Tried Diagnostics ==
I just tried running the Excel diagnostics and it found no problems. It is strange, it is like this macro has somehow became global or stored in some type of cache or something.
I hope I'm understanding your issue correctly.
If you know what right-click (context) menus the button is appearing in you should be able to fix them with a Reset command. For example if it's appearing in the Cell context menu, you could try this in the VBE's Immediate window:
Application.Commandbars("Cell").Reset
This will reset the entire menu to its default state.
Also, you might be interested in a tool I wrote, MenuRighter, that allows you to tweak your right-click menus. It also has a setting to show you the Caption and ID of any context menu.

Resources