S
StargateFanFromWork
Oh, this is disappointing. I thought this was all done <g>.
I have this code for a commandbar. It works absolutely wonderfully so far,
for the most part:
************************************
Option Explicit
Dim myBar As CommandBar
Dim myButton As CommandBarButton
Const myName As String = "Time Sheet"
Sub Autpen()
On Error Resume Next
Application.CommandBars(myName).Delete
Set myBar = Application.CommandBars.Add(myName)
With myBar
.Position = msoBarFloating
.Left = 665
.Top = 145
.Visible = True
.Enabled = True
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Add a new sheet"
.Style = msoButtonIcon
.FaceId = 2054 'or use 366 for a sheet image
.Enabled = True
.OnAction = "NewSheet_Add"
End With
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Click to enter a start date."
.Style = msoButtonIcon
.FaceId = 2473
.Enabled = True
.OnAction = "StartDate"
End With
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Help"
.Style = msoButtonIcon
.FaceId = 49
.Enabled = True
.OnAction = "Help"
End With
End With
End Sub
Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Before:=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
End Sub
Sub StartDate()
Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter the first working day of the month in
question in the box below:" & vbCrLf & vbCrLf & _
"(Excel is flexible; you can pretty much type any date
format and it'll know what date you mean!)", _
Title:="Overtime Start Date", _
Default:=Format(Date, "mmm dd, yyyy"), _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until IsDate(vResponse)
Range("B1").Value = Format(CDate(vResponse), "dddd")
Range("B2").Value = Format(CDate(vResponse), "mmm dd, yyyy")
End Sub
Sub Help()
MsgBox "The Help info is under construction and coming soon!"
End Sub
Sub Auto_Close()
'this runs on closing the workbook
On Error Resume Next
Application.CommandBars("MyToolbar").Delete
End Sub
************************************
I found the Auto_Close code on this msg here:
http://groups.google.ca/group/micro...ndBars(myName).Delete&rnum=3#e37d9a4046befcf0
with title "Adding & Removing Custom CommandBars". I've obviously missed
something because the commandbar persists even after closing the workbook.
And I prefer doing something upon closing workbook rather than relying on
user closing bar.
The other difficult behaviour to contend with is that once this file is open
and the commandbar is available, if you click to any other open workbook,
this floating toolbar comes along for the ride! <sigh> This was not what I
envisioned when I went to the trouble of replacing all my buttons and
assigned macros with this toolbar <g>. It's really great to have this, but
not with the behaviour as it is at present.
I'm guessing I've done something wrong with the closing code., and is there
anything that can be done to have access to this toolbar _only_ when the
pertinent workbook is open?
Thank you!
I have this code for a commandbar. It works absolutely wonderfully so far,
for the most part:
************************************
Option Explicit
Dim myBar As CommandBar
Dim myButton As CommandBarButton
Const myName As String = "Time Sheet"
Sub Autpen()
On Error Resume Next
Application.CommandBars(myName).Delete
Set myBar = Application.CommandBars.Add(myName)
With myBar
.Position = msoBarFloating
.Left = 665
.Top = 145
.Visible = True
.Enabled = True
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Add a new sheet"
.Style = msoButtonIcon
.FaceId = 2054 'or use 366 for a sheet image
.Enabled = True
.OnAction = "NewSheet_Add"
End With
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Click to enter a start date."
.Style = msoButtonIcon
.FaceId = 2473
.Enabled = True
.OnAction = "StartDate"
End With
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Help"
.Style = msoButtonIcon
.FaceId = 49
.Enabled = True
.OnAction = "Help"
End With
End With
End Sub
Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Before:=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
End Sub
Sub StartDate()
Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter the first working day of the month in
question in the box below:" & vbCrLf & vbCrLf & _
"(Excel is flexible; you can pretty much type any date
format and it'll know what date you mean!)", _
Title:="Overtime Start Date", _
Default:=Format(Date, "mmm dd, yyyy"), _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until IsDate(vResponse)
Range("B1").Value = Format(CDate(vResponse), "dddd")
Range("B2").Value = Format(CDate(vResponse), "mmm dd, yyyy")
End Sub
Sub Help()
MsgBox "The Help info is under construction and coming soon!"
End Sub
Sub Auto_Close()
'this runs on closing the workbook
On Error Resume Next
Application.CommandBars("MyToolbar").Delete
End Sub
************************************
I found the Auto_Close code on this msg here:
http://groups.google.ca/group/micro...ndBars(myName).Delete&rnum=3#e37d9a4046befcf0
with title "Adding & Removing Custom CommandBars". I've obviously missed
something because the commandbar persists even after closing the workbook.
And I prefer doing something upon closing workbook rather than relying on
user closing bar.
The other difficult behaviour to contend with is that once this file is open
and the commandbar is available, if you click to any other open workbook,
this floating toolbar comes along for the ride! <sigh> This was not what I
envisioned when I went to the trouble of replacing all my buttons and
assigned macros with this toolbar <g>. It's really great to have this, but
not with the behaviour as it is at present.
I'm guessing I've done something wrong with the closing code., and is there
anything that can be done to have access to this toolbar _only_ when the
pertinent workbook is open?
Thank you!