View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bradley Dawson Bradley Dawson is offline
external usenet poster
 
Posts: 23
Default Beginner question: where to put code when form loads

The UserForm_Initialize sub is the place to put much of this. Double click
the userform to go
to the code window. You'll be in the UserForm_Click event sub, so choose
Initialize from the drop down list above the code window on the right.

Use this section to establish rowsources for comboboxes and listboxes and
fill textboxes and set checkboxes and option boxes. These can often be
preset from the Properties Window at design time, but is a little easier to
maintain if everything is set at run time in the initialize sub.

As for your array of headers. If you need to use this array elsewhere in
the form
or in a sub in a module, you will need to extend the scope of this variable
by declaring
it as a Public variable. Do that at the top of the form's code if you are
using it in
buttons or listboxes or other controls on the form, like so:

Option Explicit
Public Headers(100) as String


If the Headers array needs to be processed in global subroutines in a Module
as well as in the form, put this at the top of the module code.

The Option Explicit is a common option that is often inserted automatically
by the Editor. It keeps you from using variables that haven't been properly
declared and helps reduce errors and bugs. Public variable declarations
come after options and before any code.