Microsoft Office Tutorials and References
In Depth Information
12.9.3 Implementing the Features of the Add-in
End With
' Add popup control if it is not already added
If sCurrentMenuItem <> "" Then
Set cbctlCurrentPopup = cbpop.Controls.Add( _
Type:=msoControlPopup, Temporary:=True)
cbctlCurrentPopup.Caption = sCurrentMenuItem
End If
' Now add the submenu item, which is a button control
With cbctlCurrentPopup.Controls.Add( _
Type:=msoControlButton, Temporary:=True)
.Caption = sCurrentSubMenuItem
.OnAction = sCurrentOnAction
.Tag = sCurrentProcedure ' to pass this on
.Parameter = sCurrentWorkbook ' to pass this on
.Enabled = ws.Cells(iCurrentRow, iEnabledColumn).Value
End With
End If
Next ' row
End Sub
12.9.3 Implementing the Features of the Add-in
We are now ready to "implement" the features of the add-in. As discussed earlier, for now we will
just supply a message box for each feature.
The ActivateSheet utility has already been taken care of, since there should be a code module
named basMain in the SRXUtils.xls project. For now, this module should contain only the
following procedure:
Public Sub ActivateSheet()
MsgBox "This is the ActivateSheet utility"
End Sub
For the printing utilities, we need a new Excel workbook. Create a new workbook and name it
Print.xls . Add a code module (with any name) containing the code shown in Example 12-13 .
Example 12-13. Code for the Printing Procedures
Public Sub PrintCharts()
MsgBox "This is the print charts utility"
End Sub
Public Sub PrintPivotTables()
MsgBox "This is the print pivot tables utility"
End Sub
Public Sub PrintSheets()
MsgBox "This is the print sheets utility"
End Sub
Now, the Print.xls workbook is an ordinary Excel workbook, so if our add-in opens this workbook
in order to call one of its procedures, the workbook will be visible to the user. This is not good.
Hence, we need to create an add-in from this worksheet as well. Let us call it Print.utl . (You can
save the worksheet under this name by placing the name in quotation marks in the File name box
in Excel's Save As dialog. If you omit the quotation marks, Excel will save the file as Print.utl.xla .)
Don't forget to perform the usual add-in creation rituals for this workbook (compile the code, set
Search JabSto ::

Custom Search