Example The User FormJnitialize Event Procedure

Private Sub UserForm Initialize()

' Fill lstSheets with the list of sheets Dim cSheets As Integer Dim i As Integer cSheets = Sheets.Count lstSheets.Clear

For i = 1 To cSheets lstSheets.AddItem Sheets(i).Name


End Sub

This code first gets the total number of sheets (worksheets and charts) in the current workbook. (We will discuss this in detail in later chapters, so don't worry about it now.) The list box is then cleared of any previous content. Then we have a For loop that adds the sheet names to the list box. This is done using the ListBox control's AddItem method. The name of a sheet is given by its Name property.

0 0

Post a comment