(Msg. 1) Posted: Wed Jul 02, 2008 7:07 am
Post subject: Attatchment detach issues VB-Help Add to elertz Archived from groups: microsoft>public>outlook>program_vba (more info?)
hi peeps thanks before hand for any help you can give,
i found this code on a website that pulls the attatchments off of the emails
and stores them into a specified folder. its brilliant except for a few tiny
gltches i have found.
1. All the emails are not being processed (i put a count in along with a
messagebox to check, i put 12 emails into the folder with only xls files but
ony 7 get transfered)
2. if the email hs multilple attatchments it only takes one
can anyone help with this? i have put below the code
thanks again
Rivers
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
sel = SubFolder.Items.Count
MsgBox sel
If Right(Atmt.FileName, 3) = "xls" Then
FileName = "C:\Documents and Settings\me\My Documents\Email
Attachments\" & Atmt.FileName
Atmt.SaveAsFile FileName
Item.Move otherInbox.Folders("Flash Processed")
i = i + 1
End If
Next Atmt
Next Item
(Msg. 2) Posted: Wed Jul 02, 2008 10:17 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
That code moves the item after processing the first attachment, so no others
can be processed. Also, in any loop where you're moving/deleting items from
a collection you should use a count down for loop, not for...each. The Items
collection count is changing as you move items so a for...each will process
only half the items in a collection:
"Rivers" <Rivers.TakeThisOut@discussions.microsoft.com> wrote in message
news:6F8D1AC6-D602-40DF-B956-6944D0AAD9E0@microsoft.com...
> hi peeps thanks before hand for any help you can give,
>
> i found this code on a website that pulls the attatchments off of the
> emails
> and stores them into a specified folder. its brilliant except for a few
> tiny
> gltches i have found.
>
> 1. All the emails are not being processed (i put a count in along with a
> messagebox to check, i put 12 emails into the folder with only xls files
> but
> ony 7 get transfered)
> 2. if the email hs multilple attatchments it only takes one
>
> can anyone help with this? i have put below the code
>
> thanks again
>
> Rivers
>
> For Each Item In SubFolder.Items
> For Each Atmt In Item.Attachments
> sel = SubFolder.Items.Count
> MsgBox sel
>
> If Right(Atmt.FileName, 3) = "xls" Then
>
> FileName = "C:\Documents and Settings\me\My Documents\Email
> Attachments\" & Atmt.FileName
> Atmt.SaveAsFile FileName
> Item.Move otherInbox.Folders("Flash Processed")
> i = i + 1
> End If
> Next Atmt
> Next Item
(Msg. 3) Posted: Wed Jul 02, 2008 10:17 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
ok ken being as though it was down to my thnking on my last query that caused
the problem in the first lace is this what you meant?
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
If Right(Atmt.FileName, 3) = "xls" Then
FileName = "\\ Flash Recieved\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
End If
Next Atmt
Next Item
For Each Item In SubFolder.Items
Item.Move otherInbox.Folders("Flash Processed")
Next Item
however my attatchments all copy across but when it comes to my for lop to
move my items to a new folder it completes half then stops??
(Msg. 4) Posted: Thu Jul 03, 2008 1:53 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
thanks anyway figured it out needed a do loop wit a for statement
Do Until itemcheck = True
If SubFolder.Items.Count <> 0 Then
For Each Item In SubFolder.Items
Item.Move otherInbox.Folders("Flash Processed")
Next Item
Else
itemcheck = True
End If
Loop
works perfectly
"Rivers" wrote:
> ok ken being as though it was down to my thnking on my last query that caused
> the problem in the first lace is this what you meant?
> For Each Item In SubFolder.Items
> For Each Atmt In Item.Attachments
>
> If Right(Atmt.FileName, 3) = "xls" Then
> FileName = "\\ Flash Recieved\" & Atmt.FileName
> Atmt.SaveAsFile FileName
> i = i + 1
> End If
> Next Atmt
> Next Item
>
> For Each Item In SubFolder.Items
> Item.Move otherInbox.Folders("Flash Processed")
> Next Item
>
> however my attatchments all copy across but when it comes to my for lop to
> move my items to a new folder it completes half then stops??
>
> thanks before hand
>
> Rivers
>
(Msg. 5) Posted: Thu Jul 03, 2008 9:55 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
You're still better off using the count down For loop I showed rather than a
For...Each loop. That's best practice when moving or deleting items from a
collection.
"Rivers" <Rivers RemoveThis @discussions.microsoft.com> wrote in message
news:71892032-4216-40EA-8E31-BE2A73B49E48@microsoft.com...
> thanks anyway figured it out needed a do loop wit a for statement
>
> Do Until itemcheck = True
> If SubFolder.Items.Count <> 0 Then
> For Each Item In SubFolder.Items
> Item.Move otherInbox.Folders("Flash Processed")
> Next Item
> Else
> itemcheck = True
> End If
> Loop
>
> works perfectly
(Msg. 6) Posted: Thu Jul 03, 2008 9:55 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Ken your right it doesnt work now it ran through once but now keeps giving
error
ive never written a step loop before can you help
Do Until SubFolder.Items.Count = 0
For Each Item In SubFolder.Items
Item.Move otherInbox.Folders("Flash Processed")
Next Item
Loop
"Ken Slovak - [MVP - Outlook]" wrote:
> You're still better off using the count down For loop I showed rather than a
> For...Each loop. That's best practice when moving or deleting items from a
> collection.
>
> --
> 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 >
>
> "Rivers" <Rivers RemoveThis @discussions.microsoft.com> wrote in message
> news:71892032-4216-40EA-8E31-BE2A73B49E48@microsoft.com...
> > thanks anyway figured it out needed a do loop wit a for statement
> >
> > Do Until itemcheck = True
> > If SubFolder.Items.Count <> 0 Then
> > For Each Item In SubFolder.Items
> > Item.Move otherInbox.Folders("Flash Processed")
> > Next Item
> > Else
> > itemcheck = True
> > End If
> > Loop
> >
> > works perfectly
>
>
(Msg. 7) Posted: Thu Jul 03, 2008 11:03 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Dim iCount As Long
iCount = SubFolder.Items.Count
Dim i As Long
For i = iCount To 1 Step -1
Item.Move otherInbox.Folders("Flash Processed")
Next
Also, Move is a function and returns an object reference to the newly moved
item. Often things work better when you get the returned object, even as a
throw-away item object that isn't used.
"Rivers" <Rivers.TakeThisOut@discussions.microsoft.com> wrote in message
news:1F177BF1-CB0A-461D-8CCB-D922FCC20CDC@microsoft.com...
> Ken your right it doesnt work now it ran through once but now keeps giving
> error
>
> ive never written a step loop before can you help
>
> Do Until SubFolder.Items.Count = 0
> For Each Item In SubFolder.Items
> Item.Move otherInbox.Folders("Flash Processed")
> Next Item
> Loop
(Msg. 8) Posted: Thu Jul 03, 2008 11:03 am
Post subject: Re: Attatchment detach issues VB-Help Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Done as requested Ken but now getting a new error message Lol,
"object variable or with block variable not set "
any ideas?
"Ken Slovak - [MVP - Outlook]" wrote:
> Dim iCount As Long
> iCount = SubFolder.Items.Count
>
> Dim i As Long
>
> For i = iCount To 1 Step -1
> Item.Move otherInbox.Folders("Flash Processed")
> Next
>
> Also, Move is a function and returns an object reference to the newly moved
> item. Often things work better when you get the returned object, even as a
> throw-away item object that isn't used.
>
> --
> 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 >
>
> "Rivers" <Rivers.DeleteThis@discussions.microsoft.com> wrote in message
> news:1F177BF1-CB0A-461D-8CCB-D922FCC20CDC@microsoft.com...
> > Ken your right it doesnt work now it ran through once but now keeps giving
> > error
> >
> > ive never written a step loop before can you help
> >
> > Do Until SubFolder.Items.Count = 0
> > For Each Item In SubFolder.Items
> > Item.Move otherInbox.Folders("Flash Processed")
> > Next Item
> > Loop
>
>
All times are: Eastern Time (US & Canada) (change) Goto page 1, 2
Page 1 of 2
You can post new topics in this forum You can 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