How to get the Excel dialog that allows to select multiple cells?



    Hi team,

    I am working on a project, and am looking for a way to click a botton on the Actions pane that opens an Excel dialog like the one in the chart data area selection that allows me to select several cells by dragging the mouse over them; even using Ctrl- and Shift for multiple selections. The resulting cells should be shown on a textbox like "A2:A7" or "A2;A4:A7".

    I am programming the application in C#.

    Thanks for your help


    Monday, July 17, 2006 8:44 PM


All replies

  • We are using Excel's Application.InputBox API in VSTO to display Input Range dialog.

    InputBox does a lot of stuff, but if the 8th argument (type) has value of 8 - it will the range selection. The return value will be the Range object. Also, you can put the default range into the box as the third argument. To get a feel for it just try this from VBA's immediaty window:

    Application.InputBox "Prompt", "Title", , , , , , 8

    See documentation for this method here:


    Tuesday, July 18, 2006 10:08 PM
  • Misha,

    Thank yor for the answer. I have only one final question. I tested the method, and saw that the returning string (rng.get_address()) does not returns a sheet name in case that you select a cell range different from the current sheet like Sheet1!$A$2:$A$5; in that case it always return $A$2:$A$5.

    Any hint how to capture also the sheet info?



    Wednesday, July 19, 2006 5:05 PM
  • You could use Parent.Name to get the name of the worksheet.

    Below is the sample VBA code:

        Sub foo()
            Dim r As Range
            Set r = Application.InputBox("moo", "moo", , , , , , 8)
            MsgBox r.Parent.Name
        End Sub

    Thursday, July 20, 2006 5:32 AM