You can do it as application events, which will work equally well in an
add-in.
Dim WithEvents app As Application
Private Sub app_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)
Application.StatusBar = Application.Sum(Target)
End Sub
Private Sub Workbook_Open()
Set app = Application
End Sub
'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code
In a tolbar button, it looke like this
Private WithEvents app As Application
Private oCtl As CommandBarControl
Private Sub app_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)
oCtl.Caption = "SUM = " & Application.Sum(Target)
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
oCtl.Delete
On Error GoTo 0
End Sub
Private Sub Workbook_Open()
Set app = Application
On Error Resume Next
oCtl.Delete
On Error GoTo 0
With Application.CommandBars("Standard")
Set oCtl = .Controls.Add(temporary:=True)
oCtl.BeginGroup = True
oCtl.Caption = "<<SUM>>"
oCtl.Style = msoButtonCaption
End With
End Sub
'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code
Hi,
Thanks for the responses.
Can the solution proposed here be made available as an VBA add-in or
must this code be added to the VBA associated directly with the sheet?
As a sumwhat unrelated question, rather than writing to a toolbar, can
you write to a field in a custom toolbar?
Many thanks again,
Aaron Fude