1

I'm trying to set up a VBS to create a meeting in a specific calendar (not default) when a command button is pressed. The code I have works but creates the meeting in the default calendar. I've tried fooling around with it but I am new to VBS (mainly used VBA). I know VBA and VBS are similar so im sure something small has to be tweaked. I want the meetings to be placed in a calendar named Test, which is under My Calendars.

Sub commandbutton1_Click()

If CommandButton1 = False Then
Dim objOL 'As Outlook.Application
Dim objAppt 'As Outlook.AppointmentItem

Const olAppointmentItem = 1
Const olMeeting = 1
Const olFree = 0


Set objOL = CreateObject("Outlook.Application")
Set objAppt = objOL.CreateItem(olAppointmentItem)

objAppt.Subject = "My Test Appointment"
objAppt.Start = #8/24/17 3:50:00 PM#
objAppt.Duration = 1
objAppt.Location = "Followup"
objAppt.Body = "Test Verbiage"
objAppt.ReminderMinutesBeforeStart = 1
objAppt.BusyStatus = olFree
objAppt.Save()
Set objAppt = Nothing
Set objOL = Nothing

End If


End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Rami
  • 1
  • 2
  • 10
  • On an off note - I'm under the impression that a VBA code cannot be executed in outlook through a command button. If I'm wrong please let me know as I prefer using VBA much more. Thanks! – Rami Aug 22 '17 at 21:39
  • 1
    Which part of your code specifies the location of where the meeting will go? – KS7X Aug 22 '17 at 23:13
  • Is it shared calendar? you need to specify the calendar name- – 0m3r Aug 23 '17 at 03:35
  • As of now it is not a shared calendar. Currently it is just a calendar I created under My Calendars named Test – Rami Aug 23 '17 at 15:08

1 Answers1

0

Try this:

Sub commandbutton1_Click()

If CommandButton1 = False Then

Const olAppointmentItem = 1
Const olMeeting = 1
Const olFree = 0

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")

Set objDictionary = CreateObject("Scripting.Dictionary")

objDictionary.Add "August 24, 2017", "My Test Appointment"


colKeys = objDictionary.Keys

For Each strKey in colKeys
dtmApptDate = strKey
strApptName = objDictionary.Item(strKey)

Set objAppt = objOutlook.CreateItem(olAppointmentItem) 
objAppt.Subject = strApptName
objAppt.Start = dtmApptDate & " 3:50 PM"
objAppt.Duration = 1
objAppt.Location = "Followup"
objAppt.Body = "Test Verbiage"
objAppt.ReminderSet = True
objAppt.ReminderMinutesBeforeStart = 1
objAppt.AllDayEvent = True
objAppt.BusyStatus = olFree
objAppt.Save
Next


End If


End Sub
Malbordio
  • 92
  • 3
  • 4
  • 20
  • 1
    Just gave it a shot. I'm given an error : Invalid procedure call or argument: 'objNamespace.GetDefaultFolder' – Rami Aug 22 '17 at 22:00
  • 1
    Remove the Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) and try again Odd, but with me nothing bad happened. I've edited the original script. Also included End if and End sub strings – Malbordio Aug 22 '17 at 22:04
  • 1
    Okay the code executes, however we're back in the same position. A meeting will be created but it is created in the default calendar. I need it to be made in the calendar that I've created named Test. – Rami Aug 23 '17 at 15:10