Search code examples
vbaexcelprintinguserform

How to show the current printer in a label when the UserForm starts?


I have set up a VBA form for the user to print a report with options. I want to display the active printer on that form using a label. When I launch the form it displays the active printer text "default printer". That label will only update to the active printer if I click on it. I have not been able to find a way to run that macro label when the form starts.

The code below is what I am using to display the active printer. I know its procedure is based on a click option. Is there a better way to do this?

Private Sub CurrentPrinterLabel_Click()
    CurrentPrinterLabel.Caption = Application.ActivePrinter
End Sub

enter image description here


Solution

  • Put your code under the UserForm's Initialize event:

    Private Sub UserForm_Initialize()
        CurrentPrinterLabel.Caption = Application.ActivePrinter
    End Sub
    

    Alternatively, you can use the Activate event if you want the label to be updated each time the form is activated.

    References: