3

I'm building an excel add in using c#, and i want the user to select a range. I have the inputbox set up and it's receiving the range fine when entered as a text. The problem is that excel is unresponsive when the inputbox is open, the user can't go over to excel and just select the range with the mouse, after i stop the debugging i get a message that the "File Now Available".

This is the part of the code

Excel.Range str = excelApp.InputBox("Select table range", "", _ 
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 8);
MessageBox.Show("range = " + this.range.get_Address());
6
  • You are saying if you type range value in the input box, it works but if you want to select using mouse then it doesn't work? Commented Nov 27, 2012 at 10:00
  • Almost accurate, it does work when i type range value. I'm not able to select using the mouse, it's like the excel is stuck, and not responding to anything. Commented Nov 27, 2012 at 10:15
  • Can you try this in Excel itself - meaning use a button, do the inputbox in excel module and try to choose the range from Excel? So you can narrow down if it's an interop issue or just Excel issue. Commented Nov 27, 2012 at 10:37
  • I'm really not sure on how to do what you say. When i go on a simple function i can select a range. I don't know how to work within excel to create an inputbox Commented Nov 27, 2012 at 10:56
  • What I meant was a simple test to do in excel vba to narrow down what gives you the issue. I am not front of a machine now. But you can try this link to get a small vba code snippet to test out excel environment for any doggey behaviour. Reference Put this code in a vba module and compile it. If you an issue I can help you when I get back to the machine....or just hope someone else would. Sorry. Commented Nov 27, 2012 at 11:27

2 Answers 2

2

This is entirely by design and standard for any Windows user interface. The InputBox function display a modal dialog. Dialogs always disable the other windows in an application. Very annoying but an important safety measure to prevent problems due to re-entrancy. This answer explains why modal dialogs behave that way.

You will have to cook up your own non-modal input form to work around that restriction. Do note the trouble you might get into when you do, as shown in the linked answer. You won't have much to fear from the user-closes-ui problem, that will kill the form as well. But definitely the user-reissues-command problem.

Sign up to request clarification or add additional context in comments.

3 Comments

This is a better explanation to the head-scratching I had. Hope it works for greenpeter. I am curious to know if it solves the issue as his current code doen't look buggy. :)
I think i understand the problem, but i don't really understand exactly it is that i need to do to solve it. i'm a beginner, more guidance would be appreciated.
Don't solve it, users are familiar with the way dialogs work.
0

Check this out: how to select an excel range using RefEdit control

I can update the code if you require. Please give it a try first.

3 Comments

Thanks, this is way over my level, i'm a total beginner.
For the link I provided, the tutorial is just there - when you try certain things you can have lots of fun :D Depends how much time you have though. Most importantly did you manage to get your issue solved and how?
No, didn't solve it. Unfortunately i don't have much time for this at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.