How do I make a userform appear on demand in Microsoft Word? - vba

I can make it popup on opening the document, but what if I close the userform and want to it to show up again in the same document? I know in excel you can add a button onto a worksheet directly and make it show the userform on click, but this button is unavailable for microsoft Word. Is there a solution besides initiating the script by hand?

To display a VBA userform, you can trigger it from a macrobutton field, from a form field, from a shape, from a QAT button or from an ActiveX button. There are probably a couple of other methods I'm not remembering at the moment. Each is a little different in the exact steps, but all will run the command:
UserFormName.Show

Related

Clicking away from userform open text box VBA Excel

I am not very good with userforms so hopefully this is an easy question.
I have a userform in a spreadsheet that opens with
UserForm1.Show False
To ensure excel can still be used while it is open. What I would like to happen is that whenever you click away from (but not close) the userform a text box is opened asking if you want to maintain the edited values or not. I can't figure out how to initiate more code when the userform is no long the point of interest. Usually items on userforms have enter and exit which I believe would do what I need but I can't find the equivalent for the actual userform.
Any advice would be appreciated.
To allow a user to enter values into excel while a form is visible, you will need to update the ShowModal property on the userform to false.
Or as you are showing the userform, you can show it vbModeless.
UserForm.Show vbModeless

Run macro by clicking away from any ActiveX textbox in a document

I'm looking for a VBA script that will run whenever I click away from any of ActiveX textboxes in the document. Another alternative would be to have it run whenever I click on any textbox (without clicking away).
How can it be done without assigning subs to each textbox individually?
Double click on your textbox and it will bring up the default method for that textbox, which in my testing is Textbox1_Change(). This method will run every time you type anything into the textbox.
You see two dropdown boxes at the top of the vba editor. Drop down on the one on the right and you'll see all the other available methods for the textbox, one of which is LostFocus which I reckon will suit your purposes. Clicking on that creates a sub that will execute every time the textbox loses focus. See how you go with that. Cheers

VBA button action issue on cell edit

I have an excel toolbar created by VBA macros. When cell is in edit mode, I'm unable to perform any toolbar actions, the event itself is not getting triggered. Button events are getting triggered when we come out of that editing cell.
Is there any way to handle this? I want to allow users to click on buttons even when cell is in editing mode.
Thanks.
VBA will never run if a cell is in edit mode. If you are typing inside a cell, VBA is halted. Infact, if you press ALT + F11 and bring up the VBA editor window, and then go to edit a cell in Excel, you'll find you cant ALT + TAB back to the editor, it's gone. You cant even get back to the editor whilst you are in edit mode. (Obviously when you click outside Excel, the cell is no longer in edit mode, so you can select it from the windows tray)
You may have to use a form to allow users to edit cells, this way VBA will still run whilst the form text box is being typed in. Then submit it to the cell when the text box is complete

Excel AddIn - Keeping windows form always visible while w/in Excel

First of all, thank you for your time and assistance in reviewing this!...
I'm trying to upgrade an Excel VBA workbook to a VSTO Excel Add-in in VB.NET using VS 2010. In the original (i.e.- VBA) version I have a modeless UserForm (called frmMain) that floats on top and is visible at all times while the user is still within the Excel application, but is not visible if the user moves to another window outside of Excel.
For example, within Excel the user can click on any worksheet tab, select any cell, etc. and the UserForm is still visible. This is exactly how I'd like it.
The problem is, that in the new VSTO add-in, I can not get the Windows form to mimic this same behavior.
I use frmMain.Show() to show the form as a modeless form, but the moment the user clicks an Excel worksheet (i.e.- activates a worksheet) the form becomes hidden behind the worksheet.
I can manually Alt-Tab to bring the form back into view, but I need it to always remain in view - floating on top of the Excel worksheets so long as the user hasn't left the Excel application.
I tried various things, including setting the form to TopMost, however, that causes the form to be TopMost everywhere - including outside of Excel. Worse than that, if the user does anything that would normally result in Excel's launching a dialog box (e.g.- closing an open workbook, raising the alert "Do you want to save the changes...") the alert dialog box itself is hidden and inaccessible behind the frmMain form (since the frmMain is TopMost).
How can I get my form to behave in the desired way (i.e.- the same way it did in VBA)?
Thanks!!!
Rob
You should take a look at Custom Task Panes which can be docked or floated within the Excel application. You could also look into the COM interfaces for a lower level connection (see related SO Post) - although Task Panes are really what this type of behavior was intended for.
This method might work (worked for me):
Create a worksheet_selectionChange event handler inside your form class
Put these lines in this event handler:
Dim FormHandle As IntPtr = Me.Handle
Me.Visible = False
Me.Show(NativeWindow.FromHandle(FormHandle))

In Excel, is there a way to determine the method being called by a password protected 3rd-party ribbon button?

I'm looking to automate a simple process in VBA and need to "click" a ribbon button. It makes the most sense to just call the button's underlying method. Is there a way to figure out what it is?
We are using Excel 2007 and 2010.
If it's Excel 2003 or earlier, you can use the CommandbarControl.Execute method. For instance:
Application.Commandbars("3rd Party Toolbar").Controls("Button to Push").Execute
There are two ways you can do this.
Right click on the toolbar and select Customise. If you right click on the button there may be details somewhere of what Macro the button is associated with.
If you record a macro and click the button. Then you can look at the VBA workspace and view the code that is generated to run your macro (which is just clicking the button you want). This will show you what method the macro clicks.