Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Taking focus off control on sheet

In my code I have used various methods to get the focus off of a Control
Toolbox control, like a combo box or check box. One I use is:

SendKeys "{ESC}"

I don't think that this is the best. But I can't find in all of the code
I've written what the other methods I've used are.

Don <www.donwiss.com (e-mail link at home page bottom).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Taking focus off control on sheet

activesheet.range("a1").select

(choose a cell of your choice?)

Don Wiss wrote:

In my code I have used various methods to get the focus off of a Control
Toolbox control, like a combo box or check box. One I use is:

SendKeys "{ESC}"

I don't think that this is the best. But I can't find in all of the code
I've written what the other methods I've used are.

Don <www.donwiss.com (e-mail link at home page bottom).


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Taking focus off control on sheet

On Thu, 03 Aug 2006, Dave Peterson wrote:

Don Wiss wrote:

In my code I have used various methods to get the focus off of a Control
Toolbox control, like a combo box or check box. One I use is:

SendKeys "{ESC}"

I don't think that this is the best. But I can't find in all of the code
I've written what the other methods I've used are.


activesheet.range("a1").select

(choose a cell of your choice?)


No. That is the worst way of doing it. You don't know where their cursor is
on the sheet and you want to put it back where it was. And you don't want
the sheet to move.

I had two more I used. One was something about an active window.

Don <www.donwiss.com (e-mail link at home page bottom).
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Taking focus off control on sheet


one possible way ??

'// Worksheet code module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On error resume next
Set Rg = Target
End Sub


'// Std Module

Public Rg As Range

Sub DoSel()
On Error Resume Next
Rg.Select
End Sub


'// called via your controls code @ the End of the controls code


eg Checkbox code

Private Sub CheckBox1_Click()
DoSel
End Su

--
Ivan F Moal

-----------------------------------------------------------------------
Ivan F Moala's Profile: http://www.excelforum.com/member.php...nfo&userid=195
View this thread: http://www.excelforum.com/showthread.php?threadid=56815

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Taking focus off control on sheet

You should have included more details of what you wanted in your original post.

Don Wiss wrote:

On Thu, 03 Aug 2006, Dave Peterson wrote:

Don Wiss wrote:

In my code I have used various methods to get the focus off of a Control
Toolbox control, like a combo box or check box. One I use is:

SendKeys "{ESC}"

I don't think that this is the best. But I can't find in all of the code
I've written what the other methods I've used are.


activesheet.range("a1").select

(choose a cell of your choice?)


No. That is the worst way of doing it. You don't know where their cursor is
on the sheet and you want to put it back where it was. And you don't want
the sheet to move.

I had two more I used. One was something about an active window.

Don <www.donwiss.com (e-mail link at home page bottom).


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Taking focus off control on sheet

ps. maybe something like:

Option Explicit
Private Sub ComboBox1_Change()
ActiveCell.Activate
'your code here
End Sub

If you're using a control (like a commandbutton from the control toolbox
toolbar), you can change the .takefocusonclick property to false.

Dave Peterson wrote:

You should have included more details of what you wanted in your original post.

Don Wiss wrote:

On Thu, 03 Aug 2006, Dave Peterson wrote:

Don Wiss wrote:

In my code I have used various methods to get the focus off of a Control
Toolbox control, like a combo box or check box. One I use is:

SendKeys "{ESC}"

I don't think that this is the best. But I can't find in all of the code
I've written what the other methods I've used are.


activesheet.range("a1").select

(choose a cell of your choice?)


No. That is the worst way of doing it. You don't know where their cursor is
on the sheet and you want to put it back where it was. And you don't want
the sheet to move.

I had two more I used. One was something about an active window.

Don <www.donwiss.com (e-mail link at home page bottom).


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Taking focus off control on sheet

On Fri, 04 Aug 2006, Dave Peterson wrote:

Option Explicit
Private Sub ComboBox1_Change()
ActiveCell.Activate
'your code here
End Sub


Yes, that looks like it would work.

Thinking about where I have done this before I found this one:

Range(ActiveCell.Address).Select

Then I think the other I've used was something like: ActiveWindow.Activate

I gather any of these are better than sending an escape.

If you're using a control (like a commandbutton from the control toolbox
toolbar), you can change the .takefocusonclick property to false.


(1) I never use a button from the Control toolbox. I see no advantages.

(2) I do use ComboBoxes, CheckBoxes, and OptionButtons, usually as I want
to be able to hide them. For some reason not all of the Forms controls are
hideable.

I did not find the .takefocusonclick property on the ComboBox properties
list. That is the only control I had a chance to check.

Don <www.donwiss.com (e-mail link at home page bottom).
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Taking focus off control on sheet

Range(ActiveCell.Address).Select
would be redundant compared to
ActiveCell.Activate
or
Selection.Select

and if the user had multiple cells selected, would not disturb them as your
choice would.

CommandButton is the only control that has a takefocusonclick property.

--
Regards,
Tom Ogilvy

"Don Wiss" wrote in message
...
On Fri, 04 Aug 2006, Dave Peterson wrote:

Option Explicit
Private Sub ComboBox1_Change()
ActiveCell.Activate
'your code here
End Sub


Yes, that looks like it would work.

Thinking about where I have done this before I found this one:

Range(ActiveCell.Address).Select

Then I think the other I've used was something like: ActiveWindow.Activate

I gather any of these are better than sending an escape.

If you're using a control (like a commandbutton from the control toolbox
toolbar), you can change the .takefocusonclick property to false.


(1) I never use a button from the Control toolbox. I see no advantages.

(2) I do use ComboBoxes, CheckBoxes, and OptionButtons, usually as I want
to be able to hide them. For some reason not all of the Forms controls are
hideable.

I did not find the .takefocusonclick property on the ComboBox properties
list. That is the only control I had a chance to check.

Don <www.donwiss.com (e-mail link at home page bottom).



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent control taking focus when accelerator key is used? Michael Jones Excel Programming 4 July 10th 06 10:40 AM
Prevent control taking focus when accelerator key is used? Michael Jones Excel Programming 0 July 9th 06 06:01 PM
Show userform without it taking focus? leah Excel Programming 2 August 10th 04 07:07 PM
After checking control checkbox returning focus to the sheet Don Wiss Excel Programming 4 May 12th 04 11:43 AM
Taking focus off a Control Checkbox Don Wiss Excel Programming 1 November 11th 03 12:18 AM


All times are GMT +1. The time now is 06:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"