I had the same trouble and the only thing that worked was this:
Private Declare Sub mouse_event Lib "user32" _
(ByVal dwflags As Long, _
ByVal dx As Long, _
ByVal dy As Long, _
ByVal cButtons As Long, _
ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Sub SendMouseLeftClick(ByVal lX As Long, ByVal lY As Long)
'NOTE: lX and lY are assumed to be Screen coordinates
' relative to the uper left corner (0,0).
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim lFlags As Long
'Set cursor position
SetCursorPos lX, lY
'Send the mouse event
lFlags = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_ABSOLUTE
mouse_event lFlags, lX, lY, 0, 0
lFlags = MOUSEEVENTF_LEFTUP Or MOUSEEVENTF_ABSOLUTE
mouse_event lFlags, lX, lY, 0, 0
End Sub
Sub FocusToExcel()
SendMouseLeftClick 100, 160
End Sub
The last Sub is the one you want to run to get the focus in Excel.
Experiment to get the coordinates right.
Put the Private declarations at the top of the module, just below Option
Explicit.
RBS