G
Guest
Hi!, here is my code, that i wirte just to move the item from some folders to
one folder specified.
When i run it, its work, but with the progress bar i just see in my form the
progree bar component that work, but the another components (label, and
button) i cannot see before its finish to move all the items.
Someone can tell me wath wrong in my Vba form???
Another question, es the Rules. I see in this forum, that cannot run rules
from code VBA. As i ask, is any way to do that without the user???? Because,
when i move all the item to the folder, i need to run the Rules. (and because
of that i move first the items, to do "Run Rules Now". But if i can do run
the rules automaticaly, i dont need to move the items.
Thanks a lot.
Ruben
Private Sub btnClose_Click()
Me.Hide
End Sub
Private Sub UserForm_Activate()
Call MoveElItems
End Sub
Private Sub MoveElistasItems()
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim objEls As Outlook.MAPIFolder
Dim ElEmail As Outlook.MailItem
On Error Resume Next
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set m_DNSBlackListItems = objInbox.Folders.Item("DNSBlackList").Items
Set m_BayesianItems = objInbox.Folders.Item("Bayesian").Items
Set m_HeaderItems = objInbox.Folders.Item("Header").Items
Set m_KeywordItems = objInbox.Folders.Item("Keyword").Items
Set objEl = objInbox.Folders.Item("El.net")
Dim totalitems As Integer
totalitems = m_DNSBlackListItems.Count + m_BayesianItems.Count +
m_HeaderItems.Count + m_KeywordItems.Count
totalProcess = 0
PBarItems.Value = 0
PBarItems.Max = totalitems
PBarItems.Min = 0
For i = m_DNSBlackListItems.Count To 1 Step -1
Set ElistasEmail = m_DNSBlackListItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
CountOfItems.Caption = ElEmail.Subject
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
For i = m_BayesianItems.Count To 1 Step -1
Set ElEmail = m_BayesianItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
For i = m_HeaderItems.Count To 1 Step -1
Set ElEmail = m_HeaderItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
For i = m_KeywordItems.Count To 1 Step -1
Set ElEmail = m_KeywordItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
btnClose.Enabled = True
End Sub
one folder specified.
When i run it, its work, but with the progress bar i just see in my form the
progree bar component that work, but the another components (label, and
button) i cannot see before its finish to move all the items.
Someone can tell me wath wrong in my Vba form???
Another question, es the Rules. I see in this forum, that cannot run rules
from code VBA. As i ask, is any way to do that without the user???? Because,
when i move all the item to the folder, i need to run the Rules. (and because
of that i move first the items, to do "Run Rules Now". But if i can do run
the rules automaticaly, i dont need to move the items.
Thanks a lot.
Ruben
Private Sub btnClose_Click()
Me.Hide
End Sub
Private Sub UserForm_Activate()
Call MoveElItems
End Sub
Private Sub MoveElistasItems()
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim objEls As Outlook.MAPIFolder
Dim ElEmail As Outlook.MailItem
On Error Resume Next
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set m_DNSBlackListItems = objInbox.Folders.Item("DNSBlackList").Items
Set m_BayesianItems = objInbox.Folders.Item("Bayesian").Items
Set m_HeaderItems = objInbox.Folders.Item("Header").Items
Set m_KeywordItems = objInbox.Folders.Item("Keyword").Items
Set objEl = objInbox.Folders.Item("El.net")
Dim totalitems As Integer
totalitems = m_DNSBlackListItems.Count + m_BayesianItems.Count +
m_HeaderItems.Count + m_KeywordItems.Count
totalProcess = 0
PBarItems.Value = 0
PBarItems.Max = totalitems
PBarItems.Min = 0
For i = m_DNSBlackListItems.Count To 1 Step -1
Set ElistasEmail = m_DNSBlackListItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
CountOfItems.Caption = ElEmail.Subject
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
For i = m_BayesianItems.Count To 1 Step -1
Set ElEmail = m_BayesianItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
For i = m_HeaderItems.Count To 1 Step -1
Set ElEmail = m_HeaderItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
For i = m_KeywordItems.Count To 1 Step -1
Set ElEmail = m_KeywordItems.Item(i)
ElEmail.Move objEl
totalProcess = totalProcess + 1
PBarItems.Value = totalProcess
Next
Set ElEmail = Nothing
btnClose.Enabled = True
End Sub