Questions tagged [userform]

A customizable GUI that interfaces easily with VBA when working with Microsoft Office products.

Userforms can be a critical part of Microsoft Office programming, especially in Word and Excel, in that they provide a surface with which you can interact with a user and that is totally under your control, making it possible to build more complex VBA applications.

Userforms can be used:

  • To collect and verify information from a user before it's entered into a worksheet or document.
  • To prompt a user with information, while allowing for customizable responses.
  • As part of an add-in to display options and control execution of a particular automation task.

Whereas a standard MsgBox or InputBox can perform some of these tasks, userforms are more robust than these options as they allow for a much higher degree of customization. For example, window size or color, user input, and code that runs within the form itself. In other words, and entire application may be built into a single userform, rather than just leaving users to click [OK].

3038 questions
27
votes
1 answer

Differences between Excel's Form Controls & ActiveX Controls

Why are there 2 types of controls available in Excel? (2 buttons, 2 combo boxes, 2 check box, etc...) What's the difference between Forms Controls and ActiveX Controls? Which one should I use? Some code samples I find online work with my…
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
27
votes
1 answer

Are there disadvantages in putting code into Userforms instead of modules?

Are there disadvantages in putting code into a VBA Userform instead of into a "normal" module? This might be a simple question but I have not found a conclusive answer to it while searching the web and stackoverflow. Background: I am developing a…
27
votes
2 answers

Passing variable from Form to Module in VBA

I have the following button on a Form: Private Sub CommandButton1_Click() Dim pass As String pass = UserForm1.TextBox1 Unload UserForm1 End Sub I then have a Module called Module1: Public Sub Login() ... UserForm1.Show …
JimmyK
  • 4,801
  • 8
  • 35
  • 47
14
votes
3 answers

Adding controls to a frame in an Excel userform with VBA

I need to create labels and buttons dynamically and then add them to a frame within a userform. How do I do this? Seems like it should be easier than it really is.
notnot
  • 4,472
  • 12
  • 46
  • 57
13
votes
3 answers

VBA - destroy a modeless UserForm instance properly

Intro: I am aware that - showing UserForms - it's best practice to handle QueryClose within the userform code (If CloseMode = vbFormControlMenu ...) doing no Unload Me therein, just a timid Me.Hide instruction (after preventing [x]-itting and…
T.M.
  • 9,436
  • 3
  • 33
  • 57
13
votes
6 answers

Remove Dynamically Added Controls from Userform

I have an Excel userform with dynamically added checkboxes. I add the checkboxes with code that looks like this: Set chkBox = Me.Controls.Add("Forms.Checkbox.1", "Checkbox" & i) I want to remove all of these checkboxes. Dim j As Integer 'Remove all…
ale10ander
  • 942
  • 5
  • 22
  • 42
13
votes
3 answers

VBA drag and drop file to user form to get filename and path

I'd like to learn a new trick, but I'm not 100% confident it is possible in VBA, but I thought I'd check with the gurus here. What I'd like to do is eschew the good-old getopenfilename or browser window (it has been really difficult to get the…
MattB
  • 2,203
  • 5
  • 26
  • 48
13
votes
6 answers

Hide close [X] button on excel vba userform for my progress bar

I created a userform to show a progress bar when the macro is still importing sheets The problem is the user can press the red [X] button that will close and interrupt the processing done. Is there a way to hide this red button of doom so that…
forums
  • 457
  • 2
  • 5
  • 18
12
votes
5 answers

Assign on-click VBA function to a dynamically created button on Excel Userform

I'm creating buttons dynamically on an Excel userform with the following code: With Me.CurrentFrame.Controls.Add("Forms.CommandButton.1") .Caption = "XYZ" .name = "AButton" .Font.Bold = True .ForeColor = &HFF& ... blah blah…
notnot
  • 4,472
  • 12
  • 46
  • 57
12
votes
3 answers

Check if userform open

I run a program which repeats itself. It should stop, when the user closes the userform. It runs without stopping. Since the program calls itself every 8 seconds, I want to check at the end if the userform is still loaded / opened. Public Sub…
Mentos
  • 1,142
  • 2
  • 10
  • 14
12
votes
3 answers

Excel - VBA : pass variable from Sub to Userform

I have read and applied solution I found on similar topics but nothing seem to work in my case. So, I want to pass a variable from one sub of my Module1 to a userform. It's a string called "provinceSugg". Here is the relevant part of my code :…
Phalanx
  • 1,217
  • 6
  • 25
  • 36
11
votes
0 answers

Why can't I `End` code while I'm subclassing without breaking everything?

Context I've written some code in VBA to subclass a userform so that ultimately I can intercept WM_TIMER messages being dispatched to it. I'm doing this instead of specifying a TIMERPROC, as it allows me to use VBA's own error handling and calling…
Greedo
  • 4,967
  • 2
  • 30
  • 78
11
votes
7 answers

Remove the scroll bar on a list box

I'm using a userForm in vba and I have a list box. I want to remove the horoz. scroll bar from the bottom. Is there a way to do this? I don't see any option in the properties box.
Mike
  • 2,293
  • 13
  • 42
  • 56
10
votes
1 answer

Display Excel Workbook on a Userform

Objective: As the title suggest, how do we display the workbook on the userform without using any third party controls. By Display, I mean show it on a userform where a user can select a worksheet and view the contents of that worksheet. This post…
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
10
votes
11 answers

Set focus back to the application window after showing userform

When showing a userform (running its Show method) it not only shows up on the screen but also takes the focus (the destination of e.g. keystrokes). Say, the userform is a custom made toolbar. Its Show fires in Workbook_Open() but the form itself is…
Greenberet
  • 490
  • 1
  • 5
  • 18
1
2 3
99 100