You my friend are an absolute star! ty very much for your time and effort!
Hope you have a great xmas!
Printable View
You my friend are an absolute star! ty very much for your time and effort!
Hope you have a great xmas!
now just gotta get it working with the other code! lol
Marked the threas as resolved but found another problem. the first time the script runs it give me an array out of bounds error. if i run it again it works????
Your welcome :)
Easiest way to determine whats happening and which line is giving the error is to step through the code. Place a breakpoint on the Private Sub part then run and when it breaks press F8 for line by line execution and see where the issue lies.
ok thanks! is there any reason why only one macro will run?? i have the attachment macro and it seems to ognore that one and just move the mail???
I guess it would depend on how its supposed to be invoked. Which is the starting point? GetFolder? I'm not sure what all your code looks like now. Are you still using any of the Rules for this?
ok do you want me to post all my code?
the rule is still running! dont know where to start with coding that if i need to
Sure but did you modify your rule to include any new code execution? How are you expecting to execute the code?
here it is
VB Code:
Private Sub Application_NewMail() SaveAttachmentsToFolder End Sub Sub SaveAttachmentsToFolder() On Error GoTo SaveAttachmentsToFolder_err Dim ns As NameSpace Dim Inbox As MAPIFolder Dim SubFolder As MAPIFolder Dim Item As Object Dim Atmt As attachment Dim FileName As String Dim i As Integer Dim varResponse As VbMsgBoxResult Set ns = GetNamespace("MAPI") Set Inbox = ns.GetDefaultFolder(olFolderInbox) Set SubFolder = Inbox.Folders("test1") ' Enter correct subfolder name. i = 0 For Each Item In SubFolder.Items For Each Atmt In Item.Attachments If Right(Atmt.FileName, 1) = "Z" Then FileName = "C:\Documents and Settings\Desktop\Attachments\" & _ Atmt.FileName Atmt.SaveAsFile FileName i = i + 1 End If Next Atmt Next Item SaveAttachmentsToFolder_exit: Set Atmt = Nothing Set Item = Nothing Set ns = Nothing Exit Sub SaveAttachmentsToFolder_err: MsgBox "An unexpected error has occurred." _ & vbCrLf & "Please note and report the following information." _ & vbCrLf & "Macro Name: GetAttachments" _ & vbCrLf & "Error Number: " & Err.Number _ & vbCrLf & "Error Description: " & Err.Description _ , vbCritical, "Error!" Resume SaveAttachmentsToFolder_exit End Sub Private Sub Form_Load() Dim oApp As Outlook.Application Dim oTest1 As Outlook.MAPIFolder Dim oTest2 As Outlook.MAPIFolder Set oApp = New Outlook.Application Set oTest1 = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("test1") 'In case the pst is not added then this line: 'oApp.GetNamespace("MAPI").Session.AddStore ("C:\") Set oTest2 = oApp.GetNamespace("MAPI").Folders("Personal Folders").Folders("test2") Dim oEmail As Outlook.MailItem Dim i As Integer For i = 1 To oTest1.Items.Count Set oEmail = oTest1.Items.Item(i) oEmail.Move oTest2 Set oEmail = Nothing Next End Sub
the rule runs, then the code executes from a new mail
Ok, you have the original code running from when a new mail arrives. Then you have this part from my example in a new sub that is not being called from anyware.
Private Sub Form_Load()
The code in the procedure should be called from your SaveAttachmentsToFolder procedure after it saves all attachments. Try changing Form_Load to MoveMails I guess. Then call MoveMails from your SaveAttachmentsToFolder and it should be all good.
here is the rule
[IMG]http://i28.photobucket.com/albums/c2...sback/rule.jpg
Seems the chain of events may be wrong.
You NewMail event procedure runs first, the the rule runs, then the vba code runs.
probably should be Rule runs, calls the SaveAttachments vba code, then that procedure calls the MoveMe code.
nope just made the change u suggested and it all works! RobDog you are the Outlook guru! thankyou so much
Thanks :D That is what I call myself when I work on Outlook threads. Its my forte! I got into the other office apps and soon changed my signature to VB/Office Guruâ„¢ :D
Glad to have helped you solve this issue and have a Merry Xmas :thumb: