473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Switch Focus to Excel with Access VBA Automation

124 100+
Hi, I am trying to figure out some way to open an Excel workbook from Access vba and have the focus automatically shift to Excel. What happens is is that the Excel workbook shows up as a blinking Excel icon in the taskbar. I call the following code from Access to open the Excel workbook.

Expand|Select|Wrap|Line Numbers
  1. Function OpenExcel(strFileName As String)
  2.  
  3. Dim XL As Excel.Application
  4. Dim WKB As New Excel.Workbook
  5.  
  6. Set XL = New Excel.Application
  7. XL.Visible = True
  8.  
  9. Set WKB = XL.Workbooks.Open(strFileName)
  10. WKB.Activate
  11.  
  12. 'WKB.Close SaveChanges:=False
  13.  
  14.  
  15. Set WKB = Nothing
  16. Set XL = Nothing
  17.  
  18.  
  19. End Function
  20.  
  21.  
Thanks in advance for any advice.
Aug 26 '13 #1

✓ answered by cjswimmer

I know this is a really old thread but I found a solution and thought I should share. You can use
Expand|Select|Wrap|Line Numbers
  1. AppActivate XL.Windows(1).Caption

4 9903
zmbd
5,501 Expert Mod 4TB
Try inserting etween lines 6 and 7:
xl.UserControl = True

I have a similar code that dumps stuff out to excel using basically Line 6, myline, 7 and the focus is left on the worksheet... (I also have code to select range a1 too)

Let us know if this works.

(you might take a look a this too: 163. Application Automation starts with Outlook; however, has an excel example too.
Aug 26 '13 #2
ADezii
8,834 Expert 8TB
If you are really stuck, you can use the API to retrieve the Window's Handle in the Task Bar, then Maximize it.
Aug 27 '13 #3
I know this is a really old thread but I found a solution and thought I should share. You can use
Expand|Select|Wrap|Line Numbers
  1. AppActivate XL.Windows(1).Caption
Mar 25 '19 #4
NeoPa
32,556 Expert Mod 16PB
Nice. I'll go ahead and set that to Best Answer.

I'm sure the other suggestions also work but this is exactly what was requested.
Mar 28 '19 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Henry | last post by:
Does anybody know how to find an opened copy of Word and switch focus to it, wait until Word is closed, before continuing my Python script? I tried to search for the answer from Google and nothing...
4
by: John Spiegel | last post by:
Hi All, Does anyone know of a site that might give some decent documentation on Excel 2000 objects, particularly their methods and parameters, in order? The little I've found so far seems to...
3
by: Pete | last post by:
Is there any possiblity of writing an Access or Visual Basic application that provides a method of sharing the window focus between Access and the Shell application? i.e....
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
1
by: cybertof | last post by:
Hello, Is there a way to connect (through automation) a c# application to a running Excel 2003 instance on a specific workbook ? In the past, i used to use GetObject(...) function in VB6. ...
3
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula...
0
by: Dylan | last post by:
I have written a program using VB.NET 2005 that writes macros for a redundant processing of data. This program works when using it on Office 2000. However, I had to change the code to work with...
3
by: hayuti | last post by:
Hi there This Question was posted on a wrong site. Just as introduction I am working in Access VBA where I coded a routine to retrive data from Access Database, exporting it on to Excel file...
1
by: Romanopoly | last post by:
Hello, I have written Code in .Net to export Data from a DataGridView to Excel, it works but the object is not released. Problem is: - The program is closed, Excel is still open, the COM object...
1
by: =?Utf-8?B?TWFyaw==?= | last post by:
What I want to do is bring data into an excel 2007 worksheet that is stored in a sql database table. The idea is to parameterize the "where" clause in the sql select statement limiting the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.