Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Remove Focus from Form

I have a form that pops up on a spreadsheet whenever certain cells are
selected. It is strickly informational, and I show it modeless. After it
displays, I can still click back on the spreadsheet and enter information,
but I would like for the focus to remain on the cell on the spreadsheet
rather than go to the form.

Is there any way to do this?

--
Bill @ UAMS
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Remove Focus from Form

You need to send a set focus message to the worksheet window. Paste
all of the following code into the userform's code module.

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias
"FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Const WM_SETFOCUS = &H7

Private Sub UserForm_Activate()
SetSheetFocus
End Sub


Private Sub SetSheetFocus()
Dim HWND_XLDesk As Long
Dim HWND_XLApp As Long
Dim HWND_XLSheet As Long
HWND_XLApp = Application.hwnd
HWND_XLDesk = FindWindowEx(HWND_XLApp, 0&, "XLDESK", vbNullString)
HWND_XLSheet = FindWindowEx(HWND_XLDesk, 0&, "EXCEL7",
ActiveWindow.Caption)
SendMessage HWND_XLSheet, WM_SETFOCUS, 0&, 0&
End Sub




Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com





On Tue, 16 Mar 2010 11:34:01 -0700, BillCPA <Bill @ UAMS wrote:

I have a form that pops up on a spreadsheet whenever certain cells are
selected. It is strickly informational, and I show it modeless. After it
displays, I can still click back on the spreadsheet and enter information,
but I would like for the focus to remain on the cell on the spreadsheet
rather than go to the form.

Is there any way to do this?

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
set focus to form Gus Chuch Excel Programming 18 December 20th 07 10:41 PM
Form focus Robert Pollock[_3_] Excel Programming 1 August 15th 07 12:55 PM
Focus in a form Robert Pollock[_3_] Excel Programming 1 August 15th 07 12:55 PM
Form Focus and SelStart Geoff[_9_] Excel Programming 0 April 4th 05 07:20 PM
User Form focus Glen Mettler[_2_] Excel Programming 3 October 10th 04 05:31 PM


All times are GMT +1. The time now is 08:37 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"