Decoding VBA Start learning

Intermediate track

Introduction to UserForms | Decoding VBA

Build a small form for parameters instead of hard-coding values in macros.

Goal

Let users pick a date range, file path, or region without editing VBA.

Outline

  1. Insert a UserForm from the VBE (Insert > UserForm).
  2. Add a Label, TextBox, and CommandButton.
  3. Handle the button click to store values in module-level variables or custom properties.

Starter pattern

' Module: modParameters
Option Explicit

Public ReportStartDate As Date
Public ReportEndDate As Date

Public Sub ShowReportForm()
    frmReportDates.Show
End Sub

In the form’s OK button:

Private Sub cmdRun_Click()
    ReportStartDate = CDate(txtStart.Value)
    ReportEndDate = CDate(txtEnd.Value)
    Me.Hide
End Sub

Next up

Advanced track: encapsulate behavior in class modules.

Back to Intermediate lessons