Excel COM Addin

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jody L. Whitlock

    #1

    Excel COM Addin

    I've gotten the COM Addin to work, my problem is this. I need to allow
    the user to select a range of cells (All in the same column) and then
    select my addin. My addin needs to pick up this range of cells and
    then parse the value of each cell in this range. I have looked,
    Googled, and thought I had it, but nadda.

    Here's the code I have at the moment:

    ' *** BEGIN CUSTOM CODE. ***
    Private Sub objCommandBarBu tton_Click(ByVa l Ctrl As
    CommandBarButto n, _
    ByRef CancelDefault As Boolean)

    Dim WkBook As Excel._Workbook = applicationObje ct.Workbooks(1)
    Dim WkSheet As Excel._Workshee t = WkBook.ActiveSh eet
    'Dim WkSheetNew As Excel._Workshee t =
    applicationObje ct.Worksheets.A dd(Nothing,
    applicationObje ct.Worksheets(1 ))
    Dim Range1 As Range = DirectCast(appl icationObject.S election,
    Excel.Range)
    Dim cell As Range
    Dim PPS As Integer = 0

    'WkSheetNew.Nam e = "SubTotals"
    MsgBox(Range1.A ddress())
    If Debugger.Launch () Then
    For Each cell In Range1.Cells
    Select Case CStr(cell.Value ).Substring(0, 3)
    Case Is = "PPS"
    PPS += 1
    End Select
    Next
    MsgBox("Found " & PPS & " Software Calls.")
    Else
    MsgBox("Couldn' t Launch the Debugger")
    End If
    End Sub
    ' *** END CUSTOM CODE. ***


    Thanks,
    Jody W
  • Carlos J. Quintero [.NET MVP]

    #2
    Re: Excel COM Addin

    Hi Jody,

    Which is the exact problem? I have not tested with .NET code, but this
    equivalen VBA macro works fine:

    ' ThisWorkBook file
    Sub MyMacro()

    Dim Range1 As Range
    Dim cell As Range
    Dim PPS As Integer

    Set Range1 = Me.Application. Selection

    PPS = 0

    MsgBox (Range1.Address ())

    For Each cell In Range1.Cells
    Select Case Mid$(CStr(cell. Value), 1, 3)
    Case Is = "PPS"
    PPS = PPS + 1
    End Select
    Next
    MsgBox ("Found " & PPS & " Software Calls.")

    End Sub

    --

    Best regards,

    Carlos J. Quintero

    MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
    You can code, design and document much faster.
    Free resources for add-in developers:
    MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.




    "Jody L. Whitlock" <tierscheiss197 7@hotmail.com> escribió en el mensaje
    news:eqeNF8SbFH A.2124@TK2MSFTN GP14.phx.gbl...[color=blue]
    > I've gotten the COM Addin to work, my problem is this. I need to allow
    > the user to select a range of cells (All in the same column) and then
    > select my addin. My addin needs to pick up this range of cells and
    > then parse the value of each cell in this range. I have looked,
    > Googled, and thought I had it, but nadda.
    >
    > Here's the code I have at the moment:
    >
    > ' *** BEGIN CUSTOM CODE. ***
    > Private Sub objCommandBarBu tton_Click(ByVa l Ctrl As
    > CommandBarButto n, _
    > ByRef CancelDefault As Boolean)
    >
    > Dim WkBook As Excel._Workbook = applicationObje ct.Workbooks(1)
    > Dim WkSheet As Excel._Workshee t = WkBook.ActiveSh eet
    > 'Dim WkSheetNew As Excel._Workshee t =
    > applicationObje ct.Worksheets.A dd(Nothing,
    > applicationObje ct.Worksheets(1 ))
    > Dim Range1 As Range = DirectCast(appl icationObject.S election,
    > Excel.Range)
    > Dim cell As Range
    > Dim PPS As Integer = 0
    >
    > 'WkSheetNew.Nam e = "SubTotals"
    > MsgBox(Range1.A ddress())
    > If Debugger.Launch () Then
    > For Each cell In Range1.Cells
    > Select Case CStr(cell.Value ).Substring(0, 3)
    > Case Is = "PPS"
    > PPS += 1
    > End Select
    > Next
    > MsgBox("Found " & PPS & " Software Calls.")
    > Else
    > MsgBox("Couldn' t Launch the Debugger")
    > End If
    > End Sub
    > ' *** END CUSTOM CODE. ***
    >
    >
    > Thanks,
    > Jody W[/color]


    Comment

    • Jody L. Whitlock

      #3
      Re: Excel COM Addin

      Carlos J. Quintero [.NET MVP] wrote:
      [color=blue]
      > Hi Jody,
      >
      > Which is the exact problem? I have not tested with .NET code, but
      > this equivalen VBA macro works fine:
      >
      > ' ThisWorkBook file
      > Sub MyMacro()
      >
      > Dim Range1 As Range
      > Dim cell As Range
      > Dim PPS As Integer
      >
      > Set Range1 = Me.Application. Selection
      >
      > PPS = 0
      >
      > MsgBox (Range1.Address ())
      >
      > For Each cell In Range1.Cells
      > Select Case Mid$(CStr(cell. Value), 1, 3)
      > Case Is = "PPS"
      > PPS = PPS + 1
      > End Select
      > Next
      > MsgBox ("Found " & PPS & " Software Calls.")
      >
      > End Sub[/color]

      Sorry, I had to put that project on the backburner temporarily, but now
      I'm back to it. I will give that a try and get back with you.

      Thanks,
      Jody W

      Comment

      Working...