PDA

View Full Version : How To Create An Add-In



S M C
07-03-2011, 12:02 AM
Here's a simple way to create your own add-in. Basically, an add-in has two broad steps.

So the first step to create an add-in would be to create your sub-procedure or routine that you want to run by using your add-in.

Second, you create controls / menus for the user so that they can simply click on a button to execute your macro.

Here's the basic code that covers these two steps




Sub Auto_Open()

Dim objCB As CommandBarButton

Call Auto_Close
Set objCB = Application.CommandBars("Ply").Controls.Add(Type:=msoControlButton)
With objCB
.Style = msoButtonIconAndCaption
.Caption = "&Add Sheet..."
.OnAction = "AddSheet"
.FaceId = 245
.Visible = True
End With

End Sub

Sub Auto_Close()

On Error Resume Next
Application.CommandBars("Ply").Controls("&Add Sheet...").Delete
Err.Clear: On Error GoTo 0

End Sub
Private Sub AddSheet()

Dim sht As Object
Set sht = ActiveSheet
With Application
.EnableEvents = 0
.ScreenUpdating = 0
End With
ActiveWorkbook.Worksheets.Add After:=ActiveSheet
sht.Activate
With Application
.EnableEvents = 1
.ScreenUpdating = 1
End With

End Sub

obed_cruz
07-04-2011, 08:39 PM
Thank you.

I was looking for something like this.

Greetings.