Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email which runs an excel macro 1

Status
Not open for further replies.

Cage

MIS
Aug 25, 2002
50
CA
Hello,

I would like to have it so when I receive an email via outlook overnight it automatically runs a macro in excel. Is it possible to run the code below directly from excel, otherwise does anyone know how I can run an excel macro from outlook?

cheers

Cage

------------------
Sub Outlook_macro()

Dim ol As Outlook.Application
Set ol = CreateObject("Outlook.Application")
Dim itms As Outlook.Items
Dim itm As Object
Dim email_received As Boolean

Do
Set itms = ol.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items

For Each itm In itms
s = itm.Subject
If s = "Refresh Ready" Then email_received = True
Next

Loop Until email_received

Call excel_macro

End Sub
----------------------------------

 
Why not an Outlook VBA procedure ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Good question, I think the reason being that I would have at least two excel sessions open (at least two) and didnt know/think it is possible to distigush between them, therefore I am running the macro from a specific session of Excel. Ideally I would like to have it so the email received by outlook would then run a macro (from outlook) which would manipulate Excel session A then manipulate Excel session B. Is it possible to have session of excel/outlook manipulate another session of excel without using sendkeys or sendmessage?

Cage
 
Take a look at the GetObject function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, I have searched on tek-tips for the getobject command and have found two possible ways of controlling another excel session. However is it possible to control an excel session which is currently active, instead of opening a new session.

Regards,

Cage

Dim xlApp As New Excel.Application
Dim xlWB As Excel.Workbook

Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Open("H:\myspreadsheet.xls")

with xlwb
Code:
end with


or

Dim xlApp As Object
Dim xlWB As Object

Set xlApp = GetObject(, "Excel.Application")
Set xlWB = xlApp.Workbooks.Open("h:\myspreadsheet.xls")

with xlwb
[code]
end with
 
After this line:
Set xlApp = GetObject(, "Excel.Application")
You can browse the xlApp.Workbooks collection to see if this is the one you want to control.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top