Outlook Send Meeting Invite / Appointment

vbafasttrack

New Member
Joined
Sep 13, 2012
Messages
2
Hi,

I am trying to get meeting invites sent from Outllok via Excel vba. THe below code works fine (albeit with the usual warnings) with an 'open' visible instance of Outlook present (i.e. when I have previously opened Outlook manually then subsequently run the code) but NOT when Outlook was not opened previously:

Code:
'// At this point, we have an oOutlook Appointment object and can now set some of its properties...
With olAppointment
    .MeetingStatus = 1 'olMeeting=1, olMeetingCanceled=5
    .Start = Sheets("Sheet1").Range("startdatetime").Value
    .End = .Start + TimeValue("02:00:00")
    '.Duration = "00:05"
    .Subject = "Client Quote Appointment 3"
    .Location = "TBA"
    .Body = Msg
    .BusyStatus = 2 'olBusy
    .ReminderMinutesBeforeStart = 2880
    .ReminderSet = True
    .Mileage = 22
    .Recipients.Add "email@address.com"
    .Recipients.ResolveAll
    '.Display
    '.Save
    .Send
End With

Seems to work if the display method is used when there was no previous 'open' Outlook instance. Any ideas ?

Thanks in advance.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Include this code which determines if Outlook is running and opens it if not:
Code:
    If Not IsOutlookRunning Then
        Shell "outlook.exe", vbMinimizedNoFocus
    End If
and add this function:
Code:
Private Function IsOutlookRunning() As Boolean
    Dim outlook As Object
    Set outlook = Nothing
    On Error Resume Next
    Set outlook = GetObject(, "Outlook.Application")
    On Error GoTo 0
    IsOutlookRunning = Not outlook Is Nothing
End Function
 
Upvote 0
John,

Thanks for the reply. That code will still mean that Outlook is opened and if it were not originally then I would want that to remain the case ideally. I found the solution - having to create a session with the default profile:

Code:
Dim session As Object
Set session = olApp.session.Accounts.Item(0)

Naturally you need to test for an already opened session (in the case where Outlook was already started previously) - but the above code works when there is currently no open instance of Outlook.
 
Upvote 0

Forum statistics

Threads
1,223,706
Messages
6,173,998
Members
452,542
Latest member
Bricklin

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