Solved

Activate a running Excel File from Outlook in VBA

Posted on 2009-05-06
6
525 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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 will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

729 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