Random functie fout in Outlook

Status
Niet open voor verdere reacties.

Robert09

Gebruiker
Lid geworden
6 dec 2012
Berichten
34
Hallo Allemaal,

Ik wil graag mijn mails die na 12 uur worden binnenkomen (Microsoft Outlook 2013), doorsturen naar één iemand in een lijst van 3 gebruikers welke random mails wordt verdeeld.
Ik heb het probleem dat hij de Dim randomPerson As New Random niet herkent.

Code:
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' A Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothin
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim lijst() As String
Dim words As String
words = "email-adres*email-adres*email-adres"
lijst = Split(words, "*")
Dim randomPerson As New Random
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Time for forwarding emails
bolTimeMatch = (Time >= #11:00:00 AM#) And (Time <= #11:59:59 PM#)
If bolTimeMatch Then
Dim objMail As Outlook.MailItem
Set objItem = olMailItem
Set objMail = objItem.Forward
'EXTERNAL E-MAIl adress
objMail.To = lijst(randomPerson.Next(0, lijst.Length))
objMail.Send
Set objItem = Nothing
Set objMail = Nothing
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function

Weet iemand of het mogelijk is en zo ja welke functie ik kan gebruiken ?

Met vriendelijke groet,

Robert
 
Volgens mij is het resultaat van random toewijzen van emails aan 3 persoon weinig afwijkend van de toewijzing aan iedere persoon van 1/3 van de mails.
Ergo: randomiseren voegt niets toe.
 
Kunt u uitleggen hoe ik het beste de mails verdeel onder de 3 mail adressen.
Ik neem aan met het gebruik van een loop functie ?


mvg Robert
 
Sub M_snb()

Code:
With CreateObject("Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(6)
   for j =1 to .Items.count
      with .items(j)
         .forward
         .to = choose(j\3+1,"persoon1","persoon2","persoon3") & "@mail.nl" 
         .send
      End With
   next
End Sub
 
Laatst bewerkt:
Ik krijg hem niet goed werkend.
Kunt u mij vertellen wat ik hier verkeerd doe ?

Code:
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothing
End Sub

Sub M_snb()
    With CreateObject("Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(6)
    For j = 1 To .Items.Count
      With .Items(j)
         .Forward
         .To = Choose(j \ 3 + 1, "persoon1", "persoon2", "persoon3") & "@mail.com"
         .Send
      End With
   Next
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Time for forwarding emails
bolTimeMatch = (Time >= #11:00:00 AM#) And (Time <= #11:30:00 PM#)
If bolTimeMatch Then
Call M_snb
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan