Class Module question

W

WhytheQ

I've put the following code in a class module:

'**************************************
'**************************************
Option Explicit

Public WithEvents Custombutton As CommandBarButton
Public TlBar As String

Public Function CreateButton(CustomFace As Integer, CustomCaption As
String, _ CustomText As String, CustomRoutine As String, CustomStyle
As MsoButtonStyle, _ Optional CustomEnabled As Boolean)

Dim myBar As CommandBar

IIf TlBar <> "Formatting", TlBar = TlBar, TlBar = "Formatting"

Set myBar = Application.CommandBars(TlBar)
Set Custombutton = myBar.Controls.Add(Type:=msoControlButton)

With Custombutton

.FaceId = CustomFace
.Caption = CustomCaption
.TooltipText = CustomText
.OnAction = ThisWorkbook.Name & "!" & CustomRoutine
.Style = CustomStyle
.BeginGroup = True
.Enabled = CustomEnabled

End With

End Function
Public Function DestroyButton(CustomCaption As String)

On Error Resume Next

Application.CommandBars(TlBar).Controls(CustomCaption).Delete
On Error GoTo 0

End Function
Public Function CustomizedBar(WhichToolBar As String)

TlBar = WhichToolBar

End Function

'**************************************
'**************************************

In a normal module I use the following, in an autoexec routine:

'**************************************
'**************************************
Public ButtonJHFG888888 As New ClsCustomButton

sub Auto_Open()

Application.CommandBars.Add "MyToolbar"
With CommandBars("MyToolbar")
.Position = msoBarTop
.Visible = True
End With
With ButtonJHFG888888
.CustomizedBar "MyToolbar"
.CreateButton 1142, "Import Data", "Press to import
data from the P-drive", "ImportDATAflash", msoButtonIconAndCaption,
True
End With

end sub
'**************************************
'**************************************

in a lot of workbook I have set up several of this class are used and
put on the same toolbar that has been added. Is there a way to put the
toolbar creation code and creating a possible collection of buttons on
the toolbar into the class module i.e a class ClsBarAndButtons where
somehow several buttons can be created when just one instance of
ClsBarAndButtons is created ??

(as you can see I'm pretty inexperienced with Class modules!!!)

Regards,
Jason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top