msoutlook.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problems moving an email to another folder

 
Post new topic   Reply to topic    msoutlook.org Forum Index -> Outlook Program VBA
Author Message
Bill-41



Joined: 19 Feb 2008
Posts: 1

PostPosted: Tue Feb 19, 2008 4:29 pm    Post subject: Problems moving an email to another folder Reply with quote

Hi

I'm a bit new to VBA with Outlook so I'd appreciate any help. I have a
routine that saves the attachments of certain emails based on the subject.
Then I'd like to move the emails to another folder in a different pst file.
The attachments are saving fine, but the email doesn't move to the other
folder.

Here's the code .....

Dim OLF As Outlook.MAPIFolder, CurrUser As String
Dim EmailItemCount As Integer, i As Integer, EmailCount As Integer

On Error Resume Next
Set OLF = GetObject("", _

"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
EmailItemCount = OLF.Items.Count
i = 0: EmailCount = 0
' read e-mail information
While i < EmailItemCount
i = i + 1
If i Mod 50 = 0 Then Application.StatusBar = "Reading e-mail
messages " & _
Format(i / EmailItemCount, "0%") & "..."
With OLF.Items(i)
EmailCount = EmailCount + 1

If OLF.Items(i).Subject = "ADSL order over due join with Siebel
order status" Or OLF.Items(i).Subject = "Report: ADSL Past Pending without
RTI_Auto_Migration & Disconnects - Automated" Then

If .Attachments.Count > 0 Then
For Each Att In OLF.Items(i).Attachments
Filename = Filepath1 & Trim(Att.Filename)
Att.SaveAsFile Filename
'Debug.Print "i ", i, Trim(Att.Filename)
Next
End If
'trouble is with the line below...
OLF.Items(i).Move
OLF.Folders.Item("00--Bills_email").Folders("Bills email")
End If
End With
Wend
Set OLF = Nothing

Thanks for the help!

Bill

Archived from group: microsoft>public>outlook>program_vba
Back to top
View user's profile Send private message
Ken Slovak - [MVP - Outlo



Joined: 12 Aug 2007
Posts: 405

PostPosted: Tue Feb 19, 2008 7:43 pm    Post subject: Re: Problems moving an email to another folder Reply with quote

Does the target folder actually resolve as a folder and not Nothing?

Does it help if you use Move as a function and get a return object from it,
as intended?

It would be a lot easier to debug code like this if you separated things
instead of using lots of concatenated dot operators. Get the target folder
as a MAPIFolder so you know that part's working. Same for all the other
lines where you run together lots of dot operators. Otherwise it's
impossible to tell what's erroring out or just not working.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Bill-41" wrote in message @microsoft.com...
> Hi
>
> I'm a bit new to VBA with Outlook so I'd appreciate any help. I have a
> routine that saves the attachments of certain emails based on the subject.
> Then I'd like to move the emails to another folder in a different pst
> file.
> The attachments are saving fine, but the email doesn't move to the other
> folder.
>
> Here's the code .....
>
> Dim OLF As Outlook.MAPIFolder, CurrUser As String
> Dim EmailItemCount As Integer, i As Integer, EmailCount As Integer
>
> On Error Resume Next
> Set OLF = GetObject("", _
>
> "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
> EmailItemCount = OLF.Items.Count
> i = 0: EmailCount = 0
> ' read e-mail information
> While i < EmailItemCount
> i = i + 1
> If i Mod 50 = 0 Then Application.StatusBar = "Reading e-mail
> messages " & _
> Format(i / EmailItemCount, "0%") & "..."
> With OLF.Items(i)
> EmailCount = EmailCount + 1
>
> If OLF.Items(i).Subject = "ADSL order over due join with Siebel
> order status" Or OLF.Items(i).Subject = "Report: ADSL Past Pending without
> RTI_Auto_Migration & Disconnects - Automated" Then
>
> If .Attachments.Count > 0 Then
> For Each Att In OLF.Items(i).Attachments
> Filename = Filepath1 & Trim(Att.Filename)
> Att.SaveAsFile Filename
> 'Debug.Print "i ", i, Trim(Att.Filename)
> Next
> End If
> 'trouble is with the line below...
> OLF.Items(i).Move
> OLF.Folders.Item("00--Bills_email").Folders("Bills email")
> End If
> End With
> Wend
> Set OLF = Nothing
>
> Thanks for the help!
>
> Bill
>
Back to top
View user's profile Send private message
Dmitry Streblechenko



Joined: 12 Aug 2007
Posts: 220

PostPosted: Tue Feb 19, 2008 6:45 pm    Post subject: Re: Problems moving an email to another folder Reply with quote

Also, since you are deleting items from the folder, loop from count to 1
step -1, rather than from 1 to count.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Ken Slovak - [MVP - Outlook]" wrote in message %23ycIHA.5348@TK2MSFTNGP03.phx.gbl...
> Does the target folder actually resolve as a folder and not Nothing?
>
> Does it help if you use Move as a function and get a return object from
> it, as intended?
>
> It would be a lot easier to debug code like this if you separated things
> instead of using lots of concatenated dot operators. Get the target folder
> as a MAPIFolder so you know that part's working. Same for all the other
> lines where you run together lots of dot operators. Otherwise it's
> impossible to tell what's erroring out or just not working.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "Bill-41" wrote in message
> @microsoft.com...
>> Hi
>>
>> I'm a bit new to VBA with Outlook so I'd appreciate any help. I have a
>> routine that saves the attachments of certain emails based on the
>> subject.
>> Then I'd like to move the emails to another folder in a different pst
>> file.
>> The attachments are saving fine, but the email doesn't move to the other
>> folder.
>>
>> Here's the code .....
>>
>> Dim OLF As Outlook.MAPIFolder, CurrUser As String
>> Dim EmailItemCount As Integer, i As Integer, EmailCount As Integer
>>
>> On Error Resume Next
>> Set OLF = GetObject("", _
>>
>> "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
>> EmailItemCount = OLF.Items.Count
>> i = 0: EmailCount = 0
>> ' read e-mail information
>> While i < EmailItemCount
>> i = i + 1
>> If i Mod 50 = 0 Then Application.StatusBar = "Reading e-mail
>> messages " & _
>> Format(i / EmailItemCount, "0%") & "..."
>> With OLF.Items(i)
>> EmailCount = EmailCount + 1
>>
>> If OLF.Items(i).Subject = "ADSL order over due join with
>> Siebel
>> order status" Or OLF.Items(i).Subject = "Report: ADSL Past Pending
>> without
>> RTI_Auto_Migration & Disconnects - Automated" Then
>>
>> If .Attachments.Count > 0 Then
>> For Each Att In OLF.Items(i).Attachments
>> Filename = Filepath1 & Trim(Att.Filename)
>> Att.SaveAsFile Filename
>> 'Debug.Print "i ", i, Trim(Att.Filename)
>> Next
>> End If
>> 'trouble is with the line below...
>> OLF.Items(i).Move
>> OLF.Folders.Item("00--Bills_email").Folders("Bills email")
>> End If
>> End With
>> Wend
>> Set OLF = Nothing
>>
>> Thanks for the help!
>>
>> Bill
>>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
How to add an userpropertie to an email folder? Hello, I tried several things but nothing works (create or add an item to the default drafts folder, move the item to the destination folder the item) and then add the The only way to add an userproperty to an email folder is

Problems using SentonBehalfofName-Property Hi everybody, I' ve got problems, using the the programming in Outlook-VBA: Environment: Win XP SP2, Office Outlook 2002 SP3 Win 2000 Server SP4, Exchange 2000 Enterprise I have several mailboxes with different mail-adresses a

How to know the name of the form user in a folder Config Outlook 2003 SBS 2003 Hi again, I use a personal form wich allow's me to open or create Task's / Contact in diff subFolder of my public folders, the Pb is that in many case there is a customised form in that folder so when I open the item it's disp

Default Shared Journal Folder We have a Customer Management product which synchronises a number of different accounting and POS systems to custom OL Contact forms. This has been fine for 1-2 users. However, we need to make this available for multiple users, enabling them to access a c

Show this folder as an e-mail Address Book Hi, I have hear about that the property is only available for Outlook XP and above. Is there another way to do the same with another property for Outlook 2000? Thanks. (sorry for my english).
Post new topic   Reply to topic    msoutlook.org Forum Index -> Outlook Program VBA All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group