Log in

View Full Version : [SOLVED:] Option of 'Would you like to add to 'non-default' calendar?' when sending/receiving



jsunderland
07-21-2015, 02:15 AM
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



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

skatonni
07-21-2015, 12:59 PM
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

jsunderland
07-22-2015, 02:45 AM
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

jsunderland
07-22-2015, 03:08 AM
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

jsunderland
07-22-2015, 03:14 AM
Pls ignore, been fixed.

Thanks