Load Settings from txt file

Hi All,
I have been working with a Excel Macro. Here i have a form which has the following controls:
CheckBox1
CheckBox2
CheckBox3
CheckBox4
Option1
Option2

My macro form has a CommandButton which when pressed loads the settings from a text file to the controls.

However, I want the settings to load to the form atomatically as soon as the form is loaded without the need of pressing the button.

Please can someone help me in this. I am giving the macro code herewith.

Private fso As New FileSystemObject
Private strm As TextStream
Private strName As String

Private Sub Button_Click()
    GetSettings "C:\Settings.txt"
End Sub

Private Sub GetSettings(ByVal FileName As String)
    Set strm = fso.OpenTextFile(FileName, ForReading)
    With strm
        CheckBox1.Value = .ReadLine
        CheckBox2.Value = .ReadLine
        CheckBox3.Value = .ReadLine
        CheckBox4.Value = .ReadLine
        Option1.Value = .ReadLine
        Option2.Value = .ReadLine
        .Close
    End With
End Sub
Thanks in advance,
LonelySoul
LonelySoulAsked:
Who is Participating?
 
leonstrykerCommented:
LonelySoul,

You can use UserForm_Activate event to fire your code.

Private Sub UserForm_Activate()
    GetSettings "C:\Settings.txt"
End Sub


This will load your settings then the form is activated
Leon
0
 
TooKoolKrisCommented:
Is there not a Sub for Form_Load or anything like that to play with. There has to be an event that fires when the form loads you need to determine what this is and how to manipulate it.
0
 
TooKoolKrisCommented:
See I told ya there was something, just forgot what it was called.

Thanks Leonstryker
0
 
LonelySoulAuthor Commented:
Hi leonstryker and ToolKoolChris,
Thanks for the answer
LonelySoul
0
 
leonstrykerCommented:
Thanks for the grade.

Leon
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.