Passing variable string from WorkbookOpen to userform

Nyanko

Active Member
Joined
Sep 1, 2005
Messages
437
I'm trying to pass a string value from the WorkbookOpen module to a label or textbox on a userform. This will enable me to devise a custom welcome splash screen

I can't seem to pass the contents of the variable from the module to the userform. I've researched and either my search terms are wrong or I can't find the solution I'm looking for. Thought it would be simple :(
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I think that you would need do Dim the variable as Public in a standard module. It would then be available to use in the workbook code module.
 
Upvote 0
How and where is the variable declared?
Some Form event would need to read the variable; so the scope of the variable needs to be appropriate for the use.
 
Upvote 0
I think that you would need do Dim the variable as Public in a standard module. It would then be available to use in the workbook code module.

Ah I think I see. I've never passed from the workbook open/close modules. Can the Dim be in any module ??

Thanks for all the quick replies !
 
Upvote 0
You can use:
Code:
Dim frm as Userform1
Set frm = New userform1
frm.Label1.Caption= "hello"
frm.show
for example.
 
Upvote 0
Still can't get this to work ....

In my ThisWorkbook module I have :

Code:
        pwdmsg = "Warning ! Your password will expire in " & 90 - PassNo & " days  " & vbCrLf
    frmSplash.Show (pwdmsg)

and the code behind the frmSplash is :
Code:
Private Sub UserForm_Initialize()

    MyMsg = pwdmsg & vbCrLf & vbCrLf & "Hello"
    SplashBox2 = MyMsg

End Sub

I can't get the value for pwdmsg to save to the frmSplash code and am now geting mismatch 13 errors.

help ?
 
Upvote 0
If you've Dim'd pwdmsg as Public, you should need to 'pass' it to the Form.
frmSplash.Show () < The only possible parameter here is True or False to set the Modal property of the form.
 
Upvote 0
Thank you for all of your kind advise. However I still can't get this to work :(

My coding now looks like this :

In a separate module I have
Public pwdmsg As String

Private Sub Workbook_Open()
pwdmsg = "Text of the message"
frmSplash.Show
End Sub

Private Sub UserForm_Initialize()
SplashBox2.Caption = pwdmsg
End Sub

I'm missing something simple ... help !
 
Upvote 0
Where specifically (which module) is this line:
Code:
Public pwdmsg As String

Note: if you use the syntax I posted, you don't need a public variable.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top