tags:

views:

472

answers:

3

I need the "Select Data Source" dialog added to my application so that the user can manually select a range (or ranges) in Excel and the range is pasted in my text box. This functionality is everywhere in Excel (most notably when selecting a range for a chart). How can I easily do this?

+2  A: 

have you tried using the refedit control?

How to Use the RefEdit Control with a UserForm

Russ Cam
Yes, but we need to use .NET
Jason
A: 
Dim myRange As Range
  On Error Resume Next
  Set myRange = Application.InputBox(prompt:="Select the cells you want", Type:=8)
  On Error GoTo 0
  If myRange Is Nothing Then
    MsgBox "User cancelled"
  Else
    MsgBox "User selected " & myRange.Address
  End If

This will show an input dialog. Don't type anything into it, but instead, select cells with the mouse, and their address will appear in the dialog textbox. When you press OK,they should be assigned to the variable myRange.

Notes: The "Type:=8" at the end of the InputBox line tells VBA this must be a range of cells The On Error bit prevents an error if the user cancels

dbb
Thanks! Any idea how to do this in C#?
Jason
A: 

We found this, which looks like it may be perfect (.NET compatible):

HOW TO CODE A .NET REFEDIT CONTROL

Jason
Jason, you beat me to it. I was going to edit my answer to say that you can code a refedit control for .NET with the same link as you have here!
Russ Cam
Unfortunately, it doesn't work well ... :(
Jason