Solved

Activate a running Excel File from Outlook in VBA

Posted on 2009-05-06
6
524 Views
Last Modified: 2012-05-06
Hi,

I would like to know how I can activate and use macros which are in a excel file already running.

The idea is to generate a event when a mail arrived in my outlook. I filter the subject and call a procedure if it meats a certain criteria.

I know how to open new excel instance and open a file but here my excel file is running already and I have several excel application (each one a different process in the task manager) running. In each excel application I have several excel files open.

I want to use something similar to

Set Xlapp = GetObject(, "Excel.application")

But i want to test if the excel file is runiing in that application or in another one. If it's not in that one, i need to test the seconf application. If no excel application has the file open I will open it but i need to make sure it's not open already.

Then once the file is found, I want to run a macro in that file.

Thanks for your help !

0
Comment
Question by:potter09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 24315346
Use GetObject with the workbook path and assign the result to a workbook variable. If the file is already open, you will grab a reference to it; if not, it will be opened.
Regards,
Rory
0
 

Author Comment

by:potter09
ID: 24315423
Would it looks like:

Sub OpenXlFile

  Dim Xlbook as workbook  '/ ojbect which one?
  Dim TargetCell as range

  set Xlbook  = getobject("Y:\GCF\LiveFile.xls","Excel.application")

  TargetCell = Xlbook.sheets(1).range("A1").value

End Sub
0
 

Author Comment

by:potter09
ID: 24315492
I tried with

  set Xlbook  = getobject("Y:\GCF\LiveFile.xls") but I have an Automation error :

"The message filter indicated that the application is busy"

I tried with a C:\Testfile.xls (blank excel file) and it worked so i'm not sure what's going on.

On the Live file, bloomberg is runniing to have a live feed of stock market information, that's it.
0
Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

 

Author Comment

by:potter09
ID: 24315856
Ok issue solved. It had to do with the server path. I put the complete path instead of the shortcut "Y" and it worked. Thanks rorya !
0
 

Author Comment

by:potter09
ID: 24315883
Jus a question:

there is a password on the file to open. If the file is running there is no problem, but is there a way to put the password if the file is close ?

Thanks
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24316078
I don't think you can supply a password with GetObject, no.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question