Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Load Settings from txt file

Posted on 2003-11-19
5
302 Views
Last Modified: 2010-05-03
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
0
Comment
Question by:LonelySoul
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9779715
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
 
LVL 29

Accepted Solution

by:
leonstryker earned 50 total points
ID: 9779745
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
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9779996
See I told ya there was something, just forgot what it was called.

Thanks Leonstryker
0
 

Author Comment

by:LonelySoul
ID: 9785282
Hi leonstryker and ToolKoolChris,
Thanks for the answer
LonelySoul
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9786899
Thanks for the grade.

Leon
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question