date/time issue in randomizer

hearthhrob4gals

Board Regular
Joined
Aug 20, 2014
Messages
142
I need help in fixing the below script (save it as .vbs)

This code adds a randomizer (4 digit alphanumeric value) to each email received on all mailbox based on a time and date.

Currently its adding the randomizier based on the date mentioned in the script but its ignoring the time part. Need to fix the time part here
Code:
On Error Resume Next


Arr_MailBox = Array("Ideation")
Arr_Folder = Array("Inbox")
For x = 0 To 0


SharedMailBox = Arr_MailBox(x)


SharedMailBox_Folder = Arr_Folder(0)


    Set olApp = CreateObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")
    Set olFldr = olNS.Folders(SharedMailBox)
    Set olFldr = olFldr.Folders(SharedMailBox_Folder)
Const VALID_TEXT = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"




StartTime = "7/4/2018 4:02:01 PM"


EndTime = "7/4/2018 4:06:01 PM"


For Each olItem In olFldr.Items


	MailRecDate = DateValue(olItem.ReceivedTime)
	MailRecTime = TimeValue(olItem.ReceivedTime)


	If MailRecDate & " " & MailRecTime <= DateValue(EndTime) & " " & TimeValueValue(EndTime) And MailRecDate & " " & MailRecTime >= DateValue(StartTime) & " " & TimeValueValue(StartTime) Then
MsgBox "Done"		


For I = 0 To 4
        		Randomize
			sNewSearchTag = sNewSearchTag & Mid(VALID_TEXT,Round(Rnd * Len(VALID_TEXT)),1)
		Next
Set i = Null


Set vMailSubject = olItem.Subject


	If olItem.Subject = "" Then
    		olItem.Subject = "Blank" & " " & sNewSearchTag
    	Else
    		olItem.Subject = Left(olItem.Subject, 80) & " " & sNewSearchTag
    	End If
	olItem.Save
	sNewSearchTag = Null
	End If


Next
Next
On Error Goto 0
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Yuck. It's a bit messy but I've tried to clean it up. Note that you're definitely going to create a 5 character tag with this logic and you also run the risk of silent failures by turning off error checking.

Code:
Const VALID_TEXT = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

On Error Resume Next

Arr_MailBox = Array("Ideation")
Arr_Folder = Array("Inbox")

Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

For x = 0 To 0
    SharedMailBox = Arr_MailBox(x)
    SharedMailBox_Folder = Arr_Folder(0)

    Set olFldr = olNS.Folders(SharedMailBox)
    Set olFldr = olFldr.Folders(SharedMailBox_Folder)

    StartTime = DateSerial(2018, 7, 4) + TimeSerial(16, 2, 1)
    EndTime = DateSerial(2018, 7, 4) + TimeSerial(16, 6, 1)

    For Each olItem In olFldr.Items
        If olItem.ReceivedTime >= StartTime And olItem.ReceivedTime <= EndTime Then
            sNewSearchTag = ""
            For i = 0 To 4 ' This will create a 5 character search tag
                Randomize
                sNewSearchTag = sNewSearchTag & Mid(VALID_TEXT, Round(Rnd * Len(VALID_TEXT)) + 1, 1)
            Next i
    
            If olItem.Subject = "" Then
                olItem.Subject = "Blank " & sNewSearchTag
            Else
                olItem.Subject = Left(olItem.Subject, 80) & " " & sNewSearchTag
            End If
            olItem.Save
        End If
    Next olItem
Next x

On Error GoTo 0

WBD
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top