Refers to a inbuilt popup dialog in Excel which allows user to make selection within sheet range and records selected area. In this article I will take you through simple code which will help you to create your own Range Selector which you can use in your own program. Note : Range Selector is nothing but a customized version of InputBox.
As shown in above screenshot, it refers to standard Excel inbuilt Range Selection popup. Let’s do some coding to get similar feature in our own environment:
- Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
- Create Excel Addin in C# code style (Visual Studio Tools for Office)
- Create a ribbon designer and put button
var userRange = Globals.ThisAddIn.Application.InputBox("Select range to insert formula:", "VBAOVERALL Range Selector", string.Empty, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 8);
Code above has various parameters but the main parameters which we need to focus as following:
- Prompt : it states what would you like to ask from user when popup comes?
- Title : the title of your popup
- Default : a value which you would like to pass as default when popup appears
- Left : refers to left position of popup on the screen
- Top : refers to top position of popup on the screen
- HelpFile : you can associate any help file for the user guidance
- HelpContextId : refers to context id of your help topic if any
- Type : this determines type of your popup
In above all parameters I have supplied only four main parameters as Prompt, Title, Default and Type and output should look like as: