VBA - How to open the last appointment created programmatically?
I have learned how to create and save a new appointment with VBA from excel to outlook, however I would like to see some sort of confirmation that it has saved without having to switch to outlook, locate the day, and look for the appointment. The closest I have come is creating/saving, then displaying outlook calandar.
Private Sub CommandButton1_Click()
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
With olApt
.Start = Date + 1 + TimeValue("19:00:00")
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
olApp.Session.GetDefaultFolder(olFolderCalendar).Display
Set olApt = Nothing
Set olApp = Nothing
End Sub
excel vba
add a comment |
I have learned how to create and save a new appointment with VBA from excel to outlook, however I would like to see some sort of confirmation that it has saved without having to switch to outlook, locate the day, and look for the appointment. The closest I have come is creating/saving, then displaying outlook calandar.
Private Sub CommandButton1_Click()
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
With olApt
.Start = Date + 1 + TimeValue("19:00:00")
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
olApp.Session.GetDefaultFolder(olFolderCalendar).Display
Set olApt = Nothing
Set olApp = Nothing
End Sub
excel vba
You could add a message box? You could print when a new entry was created into an excel file? The only fail safe way to know is to check though...
– alowflyingpig
Dec 30 '18 at 22:53
add a comment |
I have learned how to create and save a new appointment with VBA from excel to outlook, however I would like to see some sort of confirmation that it has saved without having to switch to outlook, locate the day, and look for the appointment. The closest I have come is creating/saving, then displaying outlook calandar.
Private Sub CommandButton1_Click()
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
With olApt
.Start = Date + 1 + TimeValue("19:00:00")
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
olApp.Session.GetDefaultFolder(olFolderCalendar).Display
Set olApt = Nothing
Set olApp = Nothing
End Sub
excel vba
I have learned how to create and save a new appointment with VBA from excel to outlook, however I would like to see some sort of confirmation that it has saved without having to switch to outlook, locate the day, and look for the appointment. The closest I have come is creating/saving, then displaying outlook calandar.
Private Sub CommandButton1_Click()
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
With olApt
.Start = Date + 1 + TimeValue("19:00:00")
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
olApp.Session.GetDefaultFolder(olFolderCalendar).Display
Set olApt = Nothing
Set olApp = Nothing
End Sub
excel vba
excel vba
asked Dec 30 '18 at 19:26
user1088793user1088793
116117
116117
You could add a message box? You could print when a new entry was created into an excel file? The only fail safe way to know is to check though...
– alowflyingpig
Dec 30 '18 at 22:53
add a comment |
You could add a message box? You could print when a new entry was created into an excel file? The only fail safe way to know is to check though...
– alowflyingpig
Dec 30 '18 at 22:53
You could add a message box? You could print when a new entry was created into an excel file? The only fail safe way to know is to check though...
– alowflyingpig
Dec 30 '18 at 22:53
You could add a message box? You could print when a new entry was created into an excel file? The only fail safe way to know is to check though...
– alowflyingpig
Dec 30 '18 at 22:53
add a comment |
1 Answer
1
active
oldest
votes
You can construct a function that returns a boolean to indicate if the meeting exists or not. I made some assumptions, and made such a function. I've defined a matching meeting as one that has a matching: duration, date, and meeting Subject.
I just made this function return a Debug.Print, but once you know it exists, you can do whatever you like with this information.
Option Explicit
Public Sub Example()
Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olApt As AppointmentItem: Set olApt = olApp.CreateItem(olAppointmentItem)
Dim MeetingStartDate As Date: MeetingStartDate = Date + 1 + TimeValue("19:00:00")
With olApt
.Start = MeetingStartDate
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
If MeetingExists(MeetingStartDate, 30, "Piano lesson") Then
Debug.Print "The meeting exists!"
Else
Debug.Print "The meeting does not exist!"
End If
End Sub
'Check all meetings for that day. A match is defined as having the same meeting subject and duration
'Adapted from: https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/search-the-calendar-for-appointments-within-a-date-range-that-contain-a-specific
Public Function MeetingExists(StartDate As Date, Duration As Long, MeetingSubject As String) As Boolean
MeetingExists = False
Dim oCalendar As Outlook.Folder: Set oCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)
Dim oItems As Outlook.Items: Set oItems = oCalendar.Items
Dim oItemsInDateRange As Outlook.Items
Dim oAppt As Outlook.AppointmentItem
Dim strRestriction As String
Dim EndDate As Date
EndDate = DateAdd("d", 1, StartDate)
strRestriction = "[Start] >= '" & Format$(StartDate, "mm/dd/yyyy hh:mm AMPM") & _
"' AND [End] <= '" & Format$(EndDate, "mm/dd/yyyy hh:mm AMPM") & "'"
oItems.IncludeRecurrences = True
oItems.Sort "[Start]"
Set oItemsInDateRange = oItems.Restrict(strRestriction)
For Each oAppt In oItemsInDateRange
If oAppt.Subject = MeetingSubject And oAppt.Duration = Duration Then
MeetingExists = True
Exit Function
End If
Next
End Function
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53980729%2fvba-how-to-open-the-last-appointment-created-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can construct a function that returns a boolean to indicate if the meeting exists or not. I made some assumptions, and made such a function. I've defined a matching meeting as one that has a matching: duration, date, and meeting Subject.
I just made this function return a Debug.Print, but once you know it exists, you can do whatever you like with this information.
Option Explicit
Public Sub Example()
Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olApt As AppointmentItem: Set olApt = olApp.CreateItem(olAppointmentItem)
Dim MeetingStartDate As Date: MeetingStartDate = Date + 1 + TimeValue("19:00:00")
With olApt
.Start = MeetingStartDate
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
If MeetingExists(MeetingStartDate, 30, "Piano lesson") Then
Debug.Print "The meeting exists!"
Else
Debug.Print "The meeting does not exist!"
End If
End Sub
'Check all meetings for that day. A match is defined as having the same meeting subject and duration
'Adapted from: https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/search-the-calendar-for-appointments-within-a-date-range-that-contain-a-specific
Public Function MeetingExists(StartDate As Date, Duration As Long, MeetingSubject As String) As Boolean
MeetingExists = False
Dim oCalendar As Outlook.Folder: Set oCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)
Dim oItems As Outlook.Items: Set oItems = oCalendar.Items
Dim oItemsInDateRange As Outlook.Items
Dim oAppt As Outlook.AppointmentItem
Dim strRestriction As String
Dim EndDate As Date
EndDate = DateAdd("d", 1, StartDate)
strRestriction = "[Start] >= '" & Format$(StartDate, "mm/dd/yyyy hh:mm AMPM") & _
"' AND [End] <= '" & Format$(EndDate, "mm/dd/yyyy hh:mm AMPM") & "'"
oItems.IncludeRecurrences = True
oItems.Sort "[Start]"
Set oItemsInDateRange = oItems.Restrict(strRestriction)
For Each oAppt In oItemsInDateRange
If oAppt.Subject = MeetingSubject And oAppt.Duration = Duration Then
MeetingExists = True
Exit Function
End If
Next
End Function
add a comment |
You can construct a function that returns a boolean to indicate if the meeting exists or not. I made some assumptions, and made such a function. I've defined a matching meeting as one that has a matching: duration, date, and meeting Subject.
I just made this function return a Debug.Print, but once you know it exists, you can do whatever you like with this information.
Option Explicit
Public Sub Example()
Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olApt As AppointmentItem: Set olApt = olApp.CreateItem(olAppointmentItem)
Dim MeetingStartDate As Date: MeetingStartDate = Date + 1 + TimeValue("19:00:00")
With olApt
.Start = MeetingStartDate
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
If MeetingExists(MeetingStartDate, 30, "Piano lesson") Then
Debug.Print "The meeting exists!"
Else
Debug.Print "The meeting does not exist!"
End If
End Sub
'Check all meetings for that day. A match is defined as having the same meeting subject and duration
'Adapted from: https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/search-the-calendar-for-appointments-within-a-date-range-that-contain-a-specific
Public Function MeetingExists(StartDate As Date, Duration As Long, MeetingSubject As String) As Boolean
MeetingExists = False
Dim oCalendar As Outlook.Folder: Set oCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)
Dim oItems As Outlook.Items: Set oItems = oCalendar.Items
Dim oItemsInDateRange As Outlook.Items
Dim oAppt As Outlook.AppointmentItem
Dim strRestriction As String
Dim EndDate As Date
EndDate = DateAdd("d", 1, StartDate)
strRestriction = "[Start] >= '" & Format$(StartDate, "mm/dd/yyyy hh:mm AMPM") & _
"' AND [End] <= '" & Format$(EndDate, "mm/dd/yyyy hh:mm AMPM") & "'"
oItems.IncludeRecurrences = True
oItems.Sort "[Start]"
Set oItemsInDateRange = oItems.Restrict(strRestriction)
For Each oAppt In oItemsInDateRange
If oAppt.Subject = MeetingSubject And oAppt.Duration = Duration Then
MeetingExists = True
Exit Function
End If
Next
End Function
add a comment |
You can construct a function that returns a boolean to indicate if the meeting exists or not. I made some assumptions, and made such a function. I've defined a matching meeting as one that has a matching: duration, date, and meeting Subject.
I just made this function return a Debug.Print, but once you know it exists, you can do whatever you like with this information.
Option Explicit
Public Sub Example()
Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olApt As AppointmentItem: Set olApt = olApp.CreateItem(olAppointmentItem)
Dim MeetingStartDate As Date: MeetingStartDate = Date + 1 + TimeValue("19:00:00")
With olApt
.Start = MeetingStartDate
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
If MeetingExists(MeetingStartDate, 30, "Piano lesson") Then
Debug.Print "The meeting exists!"
Else
Debug.Print "The meeting does not exist!"
End If
End Sub
'Check all meetings for that day. A match is defined as having the same meeting subject and duration
'Adapted from: https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/search-the-calendar-for-appointments-within-a-date-range-that-contain-a-specific
Public Function MeetingExists(StartDate As Date, Duration As Long, MeetingSubject As String) As Boolean
MeetingExists = False
Dim oCalendar As Outlook.Folder: Set oCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)
Dim oItems As Outlook.Items: Set oItems = oCalendar.Items
Dim oItemsInDateRange As Outlook.Items
Dim oAppt As Outlook.AppointmentItem
Dim strRestriction As String
Dim EndDate As Date
EndDate = DateAdd("d", 1, StartDate)
strRestriction = "[Start] >= '" & Format$(StartDate, "mm/dd/yyyy hh:mm AMPM") & _
"' AND [End] <= '" & Format$(EndDate, "mm/dd/yyyy hh:mm AMPM") & "'"
oItems.IncludeRecurrences = True
oItems.Sort "[Start]"
Set oItemsInDateRange = oItems.Restrict(strRestriction)
For Each oAppt In oItemsInDateRange
If oAppt.Subject = MeetingSubject And oAppt.Duration = Duration Then
MeetingExists = True
Exit Function
End If
Next
End Function
You can construct a function that returns a boolean to indicate if the meeting exists or not. I made some assumptions, and made such a function. I've defined a matching meeting as one that has a matching: duration, date, and meeting Subject.
I just made this function return a Debug.Print, but once you know it exists, you can do whatever you like with this information.
Option Explicit
Public Sub Example()
Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olApt As AppointmentItem: Set olApt = olApp.CreateItem(olAppointmentItem)
Dim MeetingStartDate As Date: MeetingStartDate = Date + 1 + TimeValue("19:00:00")
With olApt
.Start = MeetingStartDate
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
.Save
End With
If MeetingExists(MeetingStartDate, 30, "Piano lesson") Then
Debug.Print "The meeting exists!"
Else
Debug.Print "The meeting does not exist!"
End If
End Sub
'Check all meetings for that day. A match is defined as having the same meeting subject and duration
'Adapted from: https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/search-the-calendar-for-appointments-within-a-date-range-that-contain-a-specific
Public Function MeetingExists(StartDate As Date, Duration As Long, MeetingSubject As String) As Boolean
MeetingExists = False
Dim oCalendar As Outlook.Folder: Set oCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)
Dim oItems As Outlook.Items: Set oItems = oCalendar.Items
Dim oItemsInDateRange As Outlook.Items
Dim oAppt As Outlook.AppointmentItem
Dim strRestriction As String
Dim EndDate As Date
EndDate = DateAdd("d", 1, StartDate)
strRestriction = "[Start] >= '" & Format$(StartDate, "mm/dd/yyyy hh:mm AMPM") & _
"' AND [End] <= '" & Format$(EndDate, "mm/dd/yyyy hh:mm AMPM") & "'"
oItems.IncludeRecurrences = True
oItems.Sort "[Start]"
Set oItemsInDateRange = oItems.Restrict(strRestriction)
For Each oAppt In oItemsInDateRange
If oAppt.Subject = MeetingSubject And oAppt.Duration = Duration Then
MeetingExists = True
Exit Function
End If
Next
End Function
answered Dec 31 '18 at 0:15
Ryan WildryRyan Wildry
3,4861925
3,4861925
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53980729%2fvba-how-to-open-the-last-appointment-created-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You could add a message box? You could print when a new entry was created into an excel file? The only fail safe way to know is to check though...
– alowflyingpig
Dec 30 '18 at 22:53