+ Reply to Thread
Results 1 to 1 of 1

Outlook folderid automatic email

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    2

    Outlook folderid automatic email

    hi all, i'm fairly new at VBA coding and has taking hours of searching goolge and these forums for help on each section of the code but............... i have the following code which, when outlook opens it automatically runs. It works ok if run manually once outlook has opened but if run automatically whilst outlook opens it comes across an error relating to the folderID (i presume these aren't assigned until outlook has fully opened)

    the code, checks the current date is 7 days prior to a meeting date with the subject "TEST" and then sends an email out automatically giving a reminder and again 3 days prior with a different email.

    The folder ID must be entered as it is looking in a folder which isn't my default mailbox calendar.


    Set objoutlook = GetNamespace("MAPI")
    Dim CalFolder As MAPIFolder

    'This refers to the CEO Admin (UK) calendar ID:
    Set CalFolder = Outlook.Session.GetFolderFromID("000000001ADF6F0FAD33164AA145CDD524E9CC7E01000D6A06F123737A43AAE999B0F1965903000001D8A13C0000")
    Set CalItem = CalFolder.Items
    For Each myitem In CalItem

    'Subtracts the number of days that the original notice needs to be sent out
    OrignalNotice = myitem.start(Date) - 7
    'Subtracts the number of days that the Reminder notice needs to be sent out
    ReminderNotice = myitem.start(Date) - 3

    'Checks that the subject of the meeting matches what you require
    'and checks that the current date is, that of the subtracted date above
    If (myitem.Subject = "TEST") And (Format(OriginalNotice, "dd,mm,yyyy") = Format(Date, "dd,mm,yyyy")) Then

    'creates the email that is to be sent in OrignalNotice
    Set newitem = Application.CreateItem(0)
    newitem.To = myitem.RequiredAttendees
    newitem.CC = myitem.OptionalAttendees
    newitem.Recipients.ResolveAll
    newitem.Subject = myitem.Subject
    newitem.Body = Format(myitem.start, "DD/MM/YYYY") & " " & myitem.Location
    newitem.Display
    End If

    'Checks that the subject of the meeting matches what you require
    'and checks that the current date is, that of the subtracted date above
    If (myitem.Subject = "TEST") And (Format(ReminderNotice, "dd,mm,yyyy") = Format(Date, "dd,mm,yyyy")) Then

    'creates the email that is to be sent in ReminderNotice
    Set newitem = Application.CreateItem(0)
    newitem.To = myitem.RequiredAttendees
    newitem.CC = myitem.OptionalAttendees
    newitem.Recipients.ResolveAll
    newitem.Subject = "TRM TEST"
    newitem.Body = "REMINDER OF PACK REQUIREMENTS!!" & myitem.start
    newitem.Display
    End If
    Next



    End Sub




    Thanks for any help in advance!

    Thanks again.
    Last edited by wedwards; 12-05-2012 at 05:25 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1