Vba create outlook appointment from Excel error

p.huddy

Board Regular
Joined
May 5, 2010
Messages
59
Hi,

I can't work out what the error is on this vba code. It keeps getting to .SaveAs but getting a Run-time error '287'. Does anyone have any idea?

Code:
Function MailClient()
    Const Key As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\"
    Dim ws As Object
    On Error Resume Next
    Set ws = CreateObject("WScript.Shell")
    MailClient = ws.RegRead(Key)
End Function
Sub SetAppt()

    Dim olApp As Object
    Dim olApt As Object
    Set olApp = CreateObject("Outlook.Application")
    Set olApt = olApp.CreateItem(1)
    With olApt
        .Start = Range("B4").Value + TimeValue("09:00:00")
        .End = .Start + TimeValue("00:30:00")
        .Subject = Range("A4").Value
        .Location = Range("E4").Value
        .Body = "insert guidance text here"
        .BusyStatus = olBusy
        .ReminderMinutesBeforeStart = 40
        .ReminderSet = True
        .Display
        
        .SaveAs "C:\temp\day1.ics"
        
        'Use Close to retain the new appointment within the Outlook Calendar, or Delete to delete it.
        'Both options keep the just-created .ics file
        
        .Close False
        '.Delete
    
    End With
    Set olApt = Nothing
    Set olApp = Nothing
End Sub

Thanks,
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi

It worked for me. You could try saving to a different drive to check if it is a permission issue.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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