JDias
JDias

Reputation: 170

How to select a range in Excel VSTO

I am creating an Excel VSTO Add-In in Visual Studio.

In a Dialog Box that opens when I click in the button triggering the Add-In, I would like to select a bunch of ranges.

How may I do it?

I have tried to use a Form, however I couldn't find this control (that is in a lot of Excel built-in dialog boxes) in the Toolbox... I have made also some research...

Upvotes: 1

Views: 448

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49395

You can use the Application.InputBox method which does what you are looking for. If the 8th argument (Type) has a value of 8 - it will use 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.

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

Upvotes: 2

Related Questions