Solved

Activate a running Excel File from Outlook in VBA

Posted on 2009-05-06
6
523 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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

828 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