Reputation: 15
Can someone help me with this small script I am trying to implement in VBA?
What appends is that the loop randomly stops and I can not move all the mail in "archivio" folder.
Private Sub aggiorna_click()
Dim x As Object
Dim ns As Outlook.NameSpace
Dim itm, sgsa, actionPlan, cartella, specCartella As Object
Dim olDestFolder As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set itm = ns.GetDefaultFolder(olFolderInbox)
Set sgsa = itm.Folders("SGSA")
Set actionPlan = sgsa.Folders("action plan")
Set cartella = actionPlan.Folders(tipo.Text)
Set specCartella = cartella.Folders(piano.Text)
Set olDestFolder = itm.Folders("archivio")
For Each x In specCartella.Items
x.Move olDestFolder
Next x
End Sub
Upvotes: 0
Views: 6401
Reputation: 19067
according to comments under the question, the new loop could look like this one (not tested)
Dim i As Long
For i = specCartella.Items.Count to 1 Step -1
specCartella.Items(i).Move olDestFolder
Next i
(i have just changed x with i!)
Upvotes: 1