Consulting

Results 1 to 5 of 5

Thread: Option of 'Would you like to add to 'non-default' calendar?' when sending/receiving

  1. #1

    Option of 'Would you like to add to 'non-default' calendar?' when sending/receiving

    Hello,

    I'm completely new to VBA (and Outlook) - I've tried my hand at googling/searching through this forum and others but haven't been too lucky. If this is mentioned somewhere before, if you'd point me in the right direction that would be great.

    What I would like to do is have the option to select 'yes/no' to a 'Would you like to add to 'non-default' calendar?' prompt, and be directed to the calendar if Yes, when sending or receiving emails (Outlook 2013). Note this is not for appointments, just normal messages. This way we can manage various deadlines for specific clients a bit easier.

    I've been working from the code below, which lets me mark messages as task items. I've tried to adapt it but have been completely unsuccessful - eg. from 'If 'yes' then with item...', 'Mark as task... etc' does not seem to be at all interchangeable with . A nudge in the right direction would be great.

    Thanks in advance


    HTML Code:
    Option Explicit
    Private WithEvents olSentItems As Items
    Private Sub Application_Startup()
    Dim objNS As NameSpace
    Set objNS = Application.Session
    ' instantiate objects declared WithEvents
    Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
    Set objNS = Nothing
    End Sub
    Private Sub olSentItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Dim prompt As String
    prompt$ = "Do you want to flag this message for followup?"
    If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then
    With Item
    .MarkAsTask olMarkThisWeek
    ' sets a due date in 3 days
    .TaskDueDate = Now + 2
    .ReminderSet = True
    .ReminderTime = CDate(.TaskDueDate) & " " & TimeValue("13:00:00")
    .Save
    End With
    End If
    End Sub

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try something like this.

    Private Sub olSentItems_ItemAdd(ByVal Item As Object)
    
    Dim myNms As Namespace
    Dim myNonDefCalendar As Folder
    Dim myExplorer As Explorer
    Dim prompt As String
    
    prompt$ = "Do you want to open non-default calendar?"
    If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "non-default calendar?") = vbYes Then
        Set myNms = Application.GetNamespace("MAPI")
        Set myNonDefCalendar = myNms.Folders("Mailbox name").Folders("Calendar name")    
        Set myExplorer = Application.ActiveExplorer
        myExplorer.SelectFolder myNonDefCalendar
    End If
    
    Set myNms = Nothing
    Set myNonDefCalendar = Nothing
    Set myExplorer = Nothing
    
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    Hi

    thanks for your reply.

    I see what you've done with the code and all seems to be working well but the line in red below.

    I've tried to replace "Mailbox name" my email address (namename at email.co.uk) but it comes up with "Compile Error. Expected: list separator or )". Also tried "Inbox", "olCalendar" and various other things. Any ideas as to why it isn't working?

    Thanks again

    Private Sub olSentItems_ItemAdd(ByVal Item As Object)

    Dim myNms As Namespace
    Dim myNonDefCalendar As Folder
    Dim myExplorer As Explorer
    Dim prompt As String

    prompt$ = "Do you want to open non-default calendar?"
    If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "non-default calendar?") = vbYes Then
    Set myNms = Application.GetNamespace("MAPI")
    Set myNonDefCalendar = myNms.Folders("Mailbox name").Folders("Calendar name")
    Set myExplorer = Application.ActiveExplorer
    myExplorer.SelectFolder myNonDefCalendar
    End If

    Set myNms = Nothing
    Set myNonDefCalendar = Nothing
    Set myExplorer = Nothing

    End Sub

  4. #4
    Please ignore last reply. Have resolved this now.

    However, I can't get both 'Mark for follow up?' and 'Add to non-default calendar?' to work (so that the prompt 'add to non..' pops up after you've answered the first prompt). The line of code "Private Sub olSentItems_ItemAdd(ByVal Item As Object)" occurs twice, in the code you've given and the code from before, and I am told the second instance of it is ambiguous.

    Any way to differentiate? Item2?

    Thanks

  5. #5
    Pls ignore, been fixed.

    Thanks

Tags for this Thread

Posting Permissions

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