S
Stu W
I have a VBA add-in that I've created for Excel. There is a user form. The
add-in creates a command button on the Standard toolbar that, when clicked,
causes the userform to display. The add-in compiles and installs without
error, and adds the button to the toolbar as expected. However when clicking
the button, Excel crashes with no warning or dialog box. I need to find out
what I'm doing that is causing the userform to cause Excel to crash. I'm
wondering if its related to not having a fully qualified object or something
like that. Any help would be appreciated.
Here's the code that invokes the user form. It is in a module called
modStartForm:
====================================================
Public Sub ShowUFMain()
On Error GoTo ErrorRoutine
ufMain.Show
ErrorRoutine:
modErrorHandle.ErrorHandling "modStartform.ShowUFMain"
End Sub
====================================================
There is some code relating to the invocation of the user form that is
associated with the user form itself. The userform is called ufMain. Here
is the relevant code:
====================================================
Private Sub UserForm_Activate()
On Error GoTo ErrorRoutine
'Populate the Project Name
If ActiveSheet.PageSetup.CenterHeader = "" Then
For mRow = 1 To 20
For mCol = 1 To 20
If Left(Cells(mRow, mCol), 8) = "PROJECT:" Then
ufMain.pg1ProjTitle_txt = Mid(Cells(mRow, mCol), 11)
Next
Next
Else
ufMain.pg1ProjTitle_txt = ActiveSheet.PageSetup.CenterHeader
End If
ErrorRoutine:
modErrorHandle.ErrorHandling "ufMain.UserForm_Activate"
End Sub
====================================================
Private Sub UserForm_Initialize()
On Error GoTo ErrorRoutine
Dim mCount, mRow, mCol As Integer
'''''''''''''''''''''''''''''''''
'Really, all this sub does is to populate the form with values
'''''''''''''''''''''''''''''''''
'Page 1
'Populate the various combo boxes
If ufMain.pg1ColorCompletedColor_ddl.ListCount = 0 Then
For mCount = 1 To 9
ufMain.pg1ColorCompletedColor_ddl.AddItem
ufMain.pg1ColorMSColor_ddl.AddItem
ufMain.pg1ColorParentColor_ddl.AddItem
ufMain.pg1ColorStartDateColor_ddl.AddItem
Next mCount
End If
'Populate rows you just created
With ufMain.pg1ColorCompletedColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
With ufMain.pg1ColorMSColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
With ufMain.pg1ColorParentColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
With ufMain.pg1ColorStartDateColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
'Initialize Reporting Period txtboxes
If ufMain.pg2ReportingMonth_txt = "" Then ufMain.pg2ReportingMonth_txt =
Month(Date) - 1
If ufMain.pg2ReportingYear_txt = "" Then ufMain.pg2ReportingYear_txt =
Year(Date)
'Initialize form fields from HKEY_CURRENT_USER registry
'First, check to see if hive keys exist, and if not, then create it
' and populate it with default values
If RegistryKeyExists(mBaseKey, mKeyName) = False Then
InitializeRegistryHive
'Now, copy values from registry into form fields
LoadRegistryValuesIntoFormPage1
LoadRegistryValuesIntoFormPage2
LoadRegistryValuesIntoFormPage3
LoadRegistryValuesIntoFormPage4
'Load the Pg1 Template Combo Boxes
LoadPg1TemplateComboBoxes
''''''''''''''''''''''''
'Add code to goto the Project Title control on page 1
''''''''''''''''''''''''''
'ufMain.MultiPage1.Pages ("Page1")
'Me.txtProjTitle.SetFocus
ErrorRoutine:
modErrorHandle.ErrorHandling "ufMain.userform_Initialize"
End Sub
add-in creates a command button on the Standard toolbar that, when clicked,
causes the userform to display. The add-in compiles and installs without
error, and adds the button to the toolbar as expected. However when clicking
the button, Excel crashes with no warning or dialog box. I need to find out
what I'm doing that is causing the userform to cause Excel to crash. I'm
wondering if its related to not having a fully qualified object or something
like that. Any help would be appreciated.
Here's the code that invokes the user form. It is in a module called
modStartForm:
====================================================
Public Sub ShowUFMain()
On Error GoTo ErrorRoutine
ufMain.Show
ErrorRoutine:
modErrorHandle.ErrorHandling "modStartform.ShowUFMain"
End Sub
====================================================
There is some code relating to the invocation of the user form that is
associated with the user form itself. The userform is called ufMain. Here
is the relevant code:
====================================================
Private Sub UserForm_Activate()
On Error GoTo ErrorRoutine
'Populate the Project Name
If ActiveSheet.PageSetup.CenterHeader = "" Then
For mRow = 1 To 20
For mCol = 1 To 20
If Left(Cells(mRow, mCol), 8) = "PROJECT:" Then
ufMain.pg1ProjTitle_txt = Mid(Cells(mRow, mCol), 11)
Next
Next
Else
ufMain.pg1ProjTitle_txt = ActiveSheet.PageSetup.CenterHeader
End If
ErrorRoutine:
modErrorHandle.ErrorHandling "ufMain.UserForm_Activate"
End Sub
====================================================
Private Sub UserForm_Initialize()
On Error GoTo ErrorRoutine
Dim mCount, mRow, mCol As Integer
'''''''''''''''''''''''''''''''''
'Really, all this sub does is to populate the form with values
'''''''''''''''''''''''''''''''''
'Page 1
'Populate the various combo boxes
If ufMain.pg1ColorCompletedColor_ddl.ListCount = 0 Then
For mCount = 1 To 9
ufMain.pg1ColorCompletedColor_ddl.AddItem
ufMain.pg1ColorMSColor_ddl.AddItem
ufMain.pg1ColorParentColor_ddl.AddItem
ufMain.pg1ColorStartDateColor_ddl.AddItem
Next mCount
End If
'Populate rows you just created
With ufMain.pg1ColorCompletedColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
With ufMain.pg1ColorMSColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
With ufMain.pg1ColorParentColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
With ufMain.pg1ColorStartDateColor_ddl
.List(0, 0) = 16777215
.List(0, 1) = "Clear"
.List(1, 0) = 12632256
.List(1, 1) = "Gray"
.List(2, 0) = 255
.List(2, 1) = "Red"
.List(3, 0) = 0
.List(3, 1) = "Black"
.List(4, 0) = 65280
.List(4, 1) = "Green"
.List(5, 0) = 65535
.List(5, 1) = "Yellow"
.List(6, 0) = 16711680
.List(6, 1) = "Blue"
.List(7, 0) = 16711935
.List(7, 1) = "Magenta"
.List(8, 0) = 16776960
.List(8, 1) = "Cyan"
End With
'Initialize Reporting Period txtboxes
If ufMain.pg2ReportingMonth_txt = "" Then ufMain.pg2ReportingMonth_txt =
Month(Date) - 1
If ufMain.pg2ReportingYear_txt = "" Then ufMain.pg2ReportingYear_txt =
Year(Date)
'Initialize form fields from HKEY_CURRENT_USER registry
'First, check to see if hive keys exist, and if not, then create it
' and populate it with default values
If RegistryKeyExists(mBaseKey, mKeyName) = False Then
InitializeRegistryHive
'Now, copy values from registry into form fields
LoadRegistryValuesIntoFormPage1
LoadRegistryValuesIntoFormPage2
LoadRegistryValuesIntoFormPage3
LoadRegistryValuesIntoFormPage4
'Load the Pg1 Template Combo Boxes
LoadPg1TemplateComboBoxes
''''''''''''''''''''''''
'Add code to goto the Project Title control on page 1
''''''''''''''''''''''''''
'ufMain.MultiPage1.Pages ("Page1")
'Me.txtProjTitle.SetFocus
ErrorRoutine:
modErrorHandle.ErrorHandling "ufMain.userform_Initialize"
End Sub