Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 22,143 times

Contents

Downloads

Related Categories

Create your own Add-Ins in VB - Creating the example

S.S. Ahmed

Creating the example

We will build a simple Add-In that will count the number of lines of code for a given program component.

To begin creating the Add-In, start a new project. Choose the AddIn project type. The AddIn project type includes many components necessary for creating VB Add-Ins. There is a form that you can modify to provide a user interface for your Add-In. There is also a designer module that contains the four methods that are needed for the Add-In's interface to VB.

Remove the Ok and Cancel buttons from the form and add the following controls to the form:

Control Type Property Value
Form Name FrmAddIn
Label Caption Line Counter
Label Caption Project
TextBox Name txtProject
Label Caption Component
TextBox Name TxtComponent
CommandButton Name CmdCountCodeLines
  Caption Count Code Lines
CommandButton Name CmdDone
  Caption Done
Label Caption Code Lines
TextBox Name txtCodeLines

Here is the code:

Public VBInstance As VBIDE.VBE
Public Connect As Connect

Option Explicit

Private Sub cmdCountCodeLines_Click()

Dim strVBProject As String
Dim strVBComponent As String
Dim objVBComponent As VBComponent

'Forms controls
strVBProject = txtProject.Text
strVBComponent = txtComponent.Text

'Set objVBComponent to the program component suggested by
'strVBProject and strVBComponent
Set objVBComponent = VBInstance.VBProjects.Item(strVBProject).VBComponents.Item(strVBComponent)

'Assign the number of lines of code (countoflines) of the component
'objVBComponent to the txtcodelines textbox
txtCodeLines.Text = Str(objVBComponent.CodeModule.CountOfLines)

End Sub

Private Sub cmdDone_Click()

'Hide the addin window
Connect.Hide

End Sub

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic web sites. He has been working with SharePoint for the last 3-4 years. He develops customized SharePoint solutions. Ahmed likes to hop into other tools as well. Ahmed has used Project Server, InfoPath and BizTalk. Ahmed enjoys travelling and has been to many parts of the world. Web: www.walisystems.com Blog: www.sharepointblogs.com/ssa

Comments

  • About Add-Ins by Mr. S.S. Ahmed

    Posted by Uma Mythreyi on 06 Dec 2005

    Mr. S.S. Ahmed's Create your own Add-Ins in VB is a perect guide to create Add-Ins.
    It helped to create my Add-In in just 5 minutes. An Excellent guide.