mpaneitz
05-18-2007, 02:43 PM
I'm having problems understanding why the code that I've got doesn't run at either open or close.
This code is attached to the sheet.
____________________________________
Option Explicit
Dim oCmdPopup As CommandBarPopup
Dim oCmdButton As CommandBarButton
Dim oCmdCtrl As CommandBarControl
Sub Auto_Open()
Set oCmdPopup = CommandBars("Worksheet Menu Bar").Controls("File")
Set oCmdButton = oCmdPopup.Controls.Add(Before:=15)
With oCmdButton
.Caption = "Change Column Widths"
.FaceId = 59
.OnAction = "ShowForm"
End With
End Sub
Sub ShowForm()
frmChangeWidth.Show
End Sub
Sub Auto_Close()
Set oCmdPopup = CommandBars("Worksheet Menu Bar").Controls("File")
For Each oCmdCtrl In oCmdPopup.Controls
If oCmdCtrl.Caption = "Change Column Widths" Then
oCmdCtrl.Delete
Exit For
End If
Next oCmdCtrl
End Sub
_______________________________________
If I run the code from the view code window it does what it's supposed to do. This is exactly the code the instructor gave us for this project. What am I missing?
This code is attached to the sheet.
____________________________________
Option Explicit
Dim oCmdPopup As CommandBarPopup
Dim oCmdButton As CommandBarButton
Dim oCmdCtrl As CommandBarControl
Sub Auto_Open()
Set oCmdPopup = CommandBars("Worksheet Menu Bar").Controls("File")
Set oCmdButton = oCmdPopup.Controls.Add(Before:=15)
With oCmdButton
.Caption = "Change Column Widths"
.FaceId = 59
.OnAction = "ShowForm"
End With
End Sub
Sub ShowForm()
frmChangeWidth.Show
End Sub
Sub Auto_Close()
Set oCmdPopup = CommandBars("Worksheet Menu Bar").Controls("File")
For Each oCmdCtrl In oCmdPopup.Controls
If oCmdCtrl.Caption = "Change Column Widths" Then
oCmdCtrl.Delete
Exit For
End If
Next oCmdCtrl
End Sub
_______________________________________
If I run the code from the view code window it does what it's supposed to do. This is exactly the code the instructor gave us for this project. What am I missing?