I have an outer loop that opens an Excel workbook and then asks the user for the number of tables to import from that workbook. Then there is an inner loop that gets the relevant number of tables and does stuff to each table. On the first pass through the outer loop the dialog that captures the number for the inner loop works as expected. It is presented and has the focus, so the user simply enters the number.
HOWEVER, second and subsequent times round the outer loop the dialog box is presented BUT when it appears, it does not have the focus, meaning the user has to first click on it before they can enter the relevant number of tables.
Any clues as to why this is happenning?
Ken
PS Yes this is Word VBA I'm talking about
dialog box not getting the focus
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: dialog box not getting the focus
Are you using InputBox, or Application.InputBox, or a userform?
Best wishes,
Hans
Hans
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: dialog box not getting the focus
An input box but I can't confirm if the code says Application.InputBox or just InputBox as I've gone home for the weekend
My guess is it will just say InputBox. Whatever the user types in goes to a variable that sets the upper limit on the loop that follows it.
Ken
My guess is it will just say InputBox. Whatever the user types in goes to a variable that sets the upper limit on the loop that follows it.
Ken
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: dialog box not getting the focus
I can't reproduce the problem in a quick test, so it most probably depends on the code that you execute inside the loops...
Best wishes,
Hans
Hans
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: dialog box not getting the focus
And as that is 'Ken Kode®', it works but it's not pretty...HansV wrote:...it most probably depends on the code...
Thanks,
Ken
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: dialog box not getting the focus
It's tempting to say something about Barbie code, but...
Best wishes,
Hans
Hans
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: dialog box not getting the focus
Best wishes,
Hans
Hans
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: dialog box not getting the focus
As an aside, there's another 'unexpected side effect'. The 'Num Lock' on my keyboard gets turned off somewhere along the line...
Ken
Ken
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: dialog box not getting the focus
Not when you remember this is 'Ken Kode®'
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: dialog box not getting the focus
Turns out it might not be so weird after all. This post on stackoverflow is talking about Access but the favoured reply says it's a bug in MS VBA. Plus, my Word VBA does use 'SendKeys' so when I get a chance that will be where I start looking:
https://stackoverflow.com/questions/259 ... ccess-form
Ken
https://stackoverflow.com/questions/259 ... ccess-form
Ken
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: dialog box not getting the focus
SendKeys has been reputedly buggy for many years now...
Best wishes,
Hans
Hans
-
- Panoramic Lounger
- Posts: 8178
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: dialog box not getting the focus
Yes, I'm aware of that but I couldn't find another way of getting at a particular tick box. There'll be a thread about it somewhere here. The stackoverflow thread though suggests a workaround so I'll try that.
Ken
Ken