excelvbabuttonlabelbyref

Implementation of check marks after the Button has been activated


The code below is the code for a label next to a button which starts certain calcualtions. When I put this code into the Tabelmodul it works just fine (when i test it through the F8 key). However, i am going to need this code for the label in the macro-modul so that when the button is pushed the Label gets startet.

The issue is when I put the code into the macromodul I Keep getting the error message "Byref argument type mismatch". Which means that some things is not defined properly.

Code in the Tablemodule:

Private Sub Button_Klicken()
Call prcSetLabel(probjLabel:=Label1)
End Sub

Private Sub prcSetLabel(ByRef probjLabel As MSForms.Label)
With probjLabel
.Caption = "P"
End With
End Sub

**strong text**

enter image description here

enter image description here


Solution

  • If the macros are where I believe they are you should be able to make the calling using this:

    Private Sub Button_Klicken()
    Call prcSetLabel Me.Label1
    End Sub
    
    Private Sub prcSetLabel(ByRef probjLabel As MSForms.Label)
    With probjLabel
    .Caption = "P"
    End With
    End Sub
    

    This is assuming your label name is Label1. If not then just change that name.