PC Review


Reply
Thread Tools Rate Thread

Call macro stored in Excel workbook from Outlook's macro

 
 
=?Utf-8?B?R3ZhcmFt?=
Guest
Posts: n/a
 
      4th Oct 2006
My target is to initiate macros in excel file when Outlook receives a new mail.

For this purposes I have 2 special Subs both in Excel file and Outlook:
1. Sub in Outlook (“NewMailEx” in “ThisOutlookSession”), which gets
MailItem’s EntryID of newly received mail message (and must initiate macros
to run in excell)
2. Sub in “C:\Test.xls” (“GetDataFromMail”), which opens mailitem's
attachment (I have to supply MailItem’s EntryID), copies it in one of it's
sheets and then begins processing of data provided there.

For clarity I'm providing both of them:

EXCEL FILE:
Sub GetDataFromMail(MailItemID as string)
Dim Attach As Outlook.Attachments
Dim myItem As Outlook.MailItem
Set myItem = Outlook.Application.Session.GetItemFromID(MailItemID)
Set Attach = myItem.Attachments
Attach.Item(1).SaveAsFile ("C:\Book1200.xls")
Workbooks.Open Filename:="C:\Book1200.xls"
Sheets("Data").Select
Cells.Select
Selection.Copy
Windows("Test.xls").Activate
Sheets("DataProcessing").Select
Cells.Select
ActiveSheet.Paste
Windows("Book1200.xls").Activate
ActiveWindow.Close SaveChanges:=False
Windows("Test.xls").Activate
Range("A1").Select
Kill ("C:\Book1200.xls")
Call StartDataProcessing 'This is another function in the
same Excel file
Else: End If
End Sub

OUTLOOK:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim MyMeil As Outlook.MailItem
Dim intInitial As Integer
Dim intFinal As Integer
Dim strEntryID As String
Dim intLength As Integer
intInitial = 1
intLength = Len(EntryIDCollection)
intFinal = InStr(intInitial, EntryIDCollection, ",")
strEntryID = Strings.Mid(EntryIDCollection, intInitial, (intLength -
intInitial) + 1)
Set MyMeil = Application.Session.GetItemFromID(strEntryID)
If MyMeil.Attachments.Count 0 Then
If Right(MyMeil.Attachments.Item(1).FileName, 4) = ".xls" And
InStr(1, MyMeil.Subject, "App - ")>0 Then
'!!!!!???? Call ??????????.GetDataFromMail(strEntryID) ' HERE IS MY PROBLEM
MyMeil.UnRead = False
MyMeil.FlagIcon = olBlueFlagIcon
MyMeil.Save
Else: End If
Else: End If
End Sub

Individually, both Subs are functioning well, but I don't know how to call
"GetDataFromMail" from "Application_NewMailEx" so
that new mail with the special excel file attachment to be processed
automatically.

Pleeease somebody help me to do this ...

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FYI: One macro really helped for capturing data from multiple workbook stored in a specific folder to one excel file only Smits Microsoft Excel Programming 0 8th Nov 2006 04:37 AM
Call macro stored in Excel workbook from Outlook's macro =?Utf-8?B?R3ZhcmFt?= Microsoft Outlook VBA Programming 5 4th Oct 2006 06:26 AM
Using a macro stored in excel's personal workbook =?Utf-8?B?Y2I=?= Microsoft Access VBA Modules 0 16th Aug 2006 04:53 PM
How to call a SQL stored procedure from a macro =?Utf-8?B?U3VzYW4=?= Microsoft Access Macros 3 1st Aug 2006 09:32 PM
How do I call an excel macro from outside the workbook? Kenji Microsoft Excel Worksheet Functions 1 1st Apr 2004 09:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:04 PM.