• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

Regain Focus After Shell Call

I have a VBA event that calls a proprietary query program to gather information, then send it to Excel. Since the Query program Opens Excel, Access loses focus and will error if I don't click on Form Icon in taskbar, to regain focus to Access, after Excel opens and before sleep timer expires.

The following is semi-pseudo code of what I am Doing:

PRG_ID = Shell(Query_Program,6)

Sleep (15000)

Set ObjExcel = GetObject(, "excel.application")
ObjExcel.Application.Visible = False
ObjExcel.Application.DisplayAlerts = False
ObjExcel.Activeworkbook.Save
ObjExcel.Quit


Any Thought???

Thanks
0
muzak
Asked:
muzak
1 Solution
 
JohnMcCannCommented:
Have you tried

Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

I assume it would work some thing like this

WinHandle = application.hWndAccessApp
PRG_ID = Shell(Query_Program,6)
Putfocus WinHandle
0
 
muzakAuthor Commented:
Mission Accomplished!!

Thanks....
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now