![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi everyone.
I have a macro program that was programmed by someone years ago that I am trying to figure out how it works. The macro would search the inbox for a specific subject line of "Workorder", Save the excel attachment to a directory and then delete the email from the inbox. It has worked for years as there was only one excel attachment to the email, but now corporate IT guys have changed email policies and as a result the macro no longer works. This is due to the email now having 2 attachments, there is the excel attachment and now an additional txt document attachment. How can I get this to look at just the Excel attachment? I'm kind of at a loss in trying to figure out how this person coded. It looks straight forward but I'm apparently missing something. Sub ExcelExtract() Dim Item, Attachments, FolderName As Object Dim myOlApp As New Outlook.Application Dim myOlExp As Outlook.Explorer Dim Folder As Outlook.MAPIFolder Dim MailItem As Outlook.MailItem Set myOlExp = myOlApp.ActiveExplorer Set nsp = myOlApp.GetNamespace("MAPI") Set Folder = nsp.GetDefaultFolder(olFolderInbox) x = 0 itemcount = Folder.Items.Count For Each myitem In Folder.Items Set Attachments = myitem.Attachments If InStr(myitem.Subject, "Workorder") 0 And myitem.Attachments.Count 0 Then mycount = mycount + 1 Next Workordercount = itemcount - mycount Do Until Folder.Items.Count = Workordercount For Each Item In Folder.Items If InStr(Item.Subject, "Workorder") 0 Then Set Attachments = Item.Attachments If Attachments.Count 0 Then x = x + 1 For i = 1 To Attachments.Count Attachments(i).SaveAsFile "C:\Worktemp\Workorder" & x & ".xls" Item.Delete Next i End If Next Loop End Sub Thanks -- Ron P |
Ads |
#2
|
|||
|
|||
![]()
* * * * * * * * * * Attachments(i).SaveAsFile "C:\Worktemp\Workorder" & x & ".xls"
On my machine, I had to use Attachments.Item(i).SaveAsFile Try checking for the extension first: If mid$(Attachments.Item(i).FileName , InStrRev(Attachments.Item(i).FileName, ".") +1) = "xls" Then Attachments(i).SaveAsFile "C:\Worktemp\Workorder" & x & ".xls" |
#3
|
|||
|
|||
![]()
Here's one way. This will loop through the emails in your default
Inbox and check each email for the word "Workorder" in the subject. If found, and there are attachments, it loops through the attachments until it finds the spreadsheet and saves it to your folder. This is air code so please test it first. HTH, JP Sub ExcelExtract2() Dim i As Long Dim Msg As Outlook.MailItem Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim MyItems As Outlook.Items Dim myAttach As Outlook.Attachments Dim Att As Outlook.Attachment Dim OrdNum As Long Set olApp = Application Set objNS = olApp.GetNamespace("MAPI") Set MyItems = objNS.GetDefaultFolder(olFolderInbox).Items For i = MyItems.Count To 1 Step -1 If MyItems.Item(i).Class = olMail Then Set Msg = MyItems.Item(i) If (InStr(Msg.Subject, "Workorder") 0) And (Msg.Attachments.Count 0) Then Set myAttach = Msg.Attachments For Each Att In myAttach If UCase$(Right$(Att.FileName, 3)) = "XLS" Then OrdNum = OrdNum + 1 Att.SaveAsFile "C:\Worktemp\Workorder" & OrdNum & ".xls" Msg.Delete End If Next Att End If End If Next i End Sub On Jul 22, 1:27*pm, Ron P wrote: Hi everyone. I have a macro program that was programmed by someone years ago that I am trying to figure out how it works. *The macro would search the inbox for a specific subject line of "Workorder", Save the excel attachment to a directory and then delete the email from the inbox. *It has worked for years as there was only one excel attachment to the email, but now corporate IT guys have changed email policies and as a result the macro no longer works. * This is due to the email now having 2 attachments, *there is the excel attachment and now an additional txt document attachment. *How can I get this to look at just the Excel attachment? *I'm kind of at a loss in trying to figure out how this person coded. *It looks straight forward but I'm apparently missing something. |
#4
|
|||
|
|||
![]()
THANKS ever so much. The information contained helped out ALOT!!!
-- Ron P "JP" wrote: Here's one way. This will loop through the emails in your default Inbox and check each email for the word "Workorder" in the subject. If found, and there are attachments, it loops through the attachments until it finds the spreadsheet and saves it to your folder. This is air code so please test it first. HTH, JP Sub ExcelExtract2() Dim i As Long Dim Msg As Outlook.MailItem Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim MyItems As Outlook.Items Dim myAttach As Outlook.Attachments Dim Att As Outlook.Attachment Dim OrdNum As Long Set olApp = Application Set objNS = olApp.GetNamespace("MAPI") Set MyItems = objNS.GetDefaultFolder(olFolderInbox).Items For i = MyItems.Count To 1 Step -1 If MyItems.Item(i).Class = olMail Then Set Msg = MyItems.Item(i) If (InStr(Msg.Subject, "Workorder") 0) And (Msg.Attachments.Count 0) Then Set myAttach = Msg.Attachments For Each Att In myAttach If UCase$(Right$(Att.FileName, 3)) = "XLS" Then OrdNum = OrdNum + 1 Att.SaveAsFile "C:\Worktemp\Workorder" & OrdNum & ".xls" Msg.Delete End If Next Att End If End If Next i End Sub On Jul 22, 1:27 pm, Ron P wrote: Hi everyone. I have a macro program that was programmed by someone years ago that I am trying to figure out how it works. The macro would search the inbox for a specific subject line of "Workorder", Save the excel attachment to a directory and then delete the email from the inbox. It has worked for years as there was only one excel attachment to the email, but now corporate IT guys have changed email policies and as a result the macro no longer works. This is due to the email now having 2 attachments, there is the excel attachment and now an additional txt document attachment. How can I get this to look at just the Excel attachment? I'm kind of at a loss in trying to figure out how this person coded. It looks straight forward but I'm apparently missing something. |
#5
|
|||
|
|||
![]()
Glad to hear it!
--JP On Jul 22, 5:46*pm, Ron P wrote: THANKS ever so much. *The information contained helped out ALOT!!! -- Ron P "JP" wrote: Here's one way. This will loop through the emails in your default Inbox and check each email for the word "Workorder" in the subject. If found, and there are attachments, it loops through the attachments until it finds the spreadsheet and saves it to your folder. This is air code so please test it first. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
macro can not get all attachments in one time | [email protected] | Outlook and VBA | 2 | April 25th 08 02:16 PM |
ANy clues on extracting attachments??? | [email protected] | Outlook and VBA | 0 | October 17th 07 03:21 PM |
Extracting Data from Attachments | mrbalaje | Outlook and VBA | 1 | September 10th 07 06:45 AM |
Extracting attachments from .pst files | schizoid_man | Outlook - General Queries | 2 | December 15th 06 09:38 AM |
vba macro to print email and attachments outlook 2000 | Dan over in IT | Outlook and VBA | 2 | June 7th 06 08:08 PM |