Set .Caption property of inactive userform label from other userform

61 Views Asked by At

I have a userform that allows users to input text that will be sent to another userform by calling the following function, where targetLabel is the intended control to accept the caption revisedStr:

Function changeMsgLabel(ByRef targetLabel As String, revisedStr As String)

    With ThisWorkbook.VBProject.VBComponents("masterMsgUserForm").Designer
        With .Controls(targetLabel)
            .Caption = revisedStr
        End With
    End With
  
End Function

I've used code blocks similar in this project to this one before with success, setting the .Name property of controls, but for some reason this gives me the error Object or with block variable not set. For full disclosure, the names of both the label and the userform are correct and the necessary libraries are included.

Any idea why this isn't working?

0

There are 0 best solutions below