0

I have a bit of code that works fine in VBA (e.g., Excel) but fails in VBScript. VBScript does not throw any errors and reports that the code completes with exit code 0, i.e., no problems. If you have Outlook installed then you can probably past the code as is into an Excel VBA and it'll run (although whoever has the someone@gmail.com account will be on your calendar.) What am I missing??

Thanks!

Sub main()
    SendCalendarAppt "strSubject", "strBody", "strLocation", "someone@gmail.com", Now()
End Sub

Sub SendCalendarAppt(strSubject, strBody, strLocation, strAttendees, datDateTime)

Dim objOL 'As Outlook.Application
Dim objAppt 'As Outlook.AppointmentItem
Const olAppointmentItem = 1
Const olMeeting = 1
Const olNonMeeting = 0

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

   objAppt.Subject = strSubject
   objAppt.Start = datDateTime
   objAppt.End = datDateTime + 1
   objAppt.Location = strLocation
   objAppt.RequiredAttendees = strAttendees
   objAppt.MeetingStatus = olMeeting
   objAppt.Send

  Set objAppt = Nothing
  Set objOL = Nothing

End Sub
bcrimmins
  • 135
  • 1
  • 1
  • 13
  • Accessing Outlook with external scripts has been heavily restricted, up to the point of complete unusability. I haven't followed along with newer versions of Outlook, but scripting became more and more difficult to use with every version (security reasons, obviously). You might have better luck using an SMTP Client tool or -library to send an actual ICS file to an Outlook user instead of trying to remote-control Outlook. This might also end up as the much faster and more portable solution. Compare https://stackoverflow.com/q/461889/18771 to get an idea how this could look like. – Tomalak May 15 '18 at 16:57
  • Thanks @Tomalak. I think you're right. I will work on an Outlook-free solution. I would be happy to use CDO, but the CDO.Appointment object apparently is only available with the CDOEX dll, i.e., with Microsoft Exchange. I've been reading up on the ICS approach but haven't been able to get that to work yet... but I'll keep trying. – bcrimmins May 15 '18 at 19:37
  • Try with Redemption. http://www.dimastr.com/redemption/home.htm – Tomalak May 16 '18 at 05:56
  • 1
    Tanks, @Tomalak. I checked out Redemption. It's clever but it requires a MAPI server via either Outlook or Exchange. I don't want the script to require access to either of those. If I'm going to install a third-party tool set then I don't want to have to also rely on Outlook. – bcrimmins May 17 '18 at 16:47

0 Answers0