• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA modification

Afarag

Member
Dears,

Kindly please i have a VBA code related to outlook appointment for more than one person, but when active VBA the appointments sent to me, but not for mentioned mails, so i want to sent each appointment to it's mail



Code:
Option Explicit

' requires a reference to the Microsoft Outlook x.0 Object Library
Sub RegisterAppointmentList()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
    DeleteTestAppointments ' deletes previous test appointments
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = CreateObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    r = 3 ' first row with appointment data in the active worksheet
    While Len(Cells(r, 1).Formula) > 0
        Set olAppItem = olApp.CreateItem(olAppointmentItem) ' creates a new appointment
        With olAppItem
            ' set default appointment values
            .Start = Now
            .End = Now
            .Subject = ""
            .Location = ""
            .Body = Cells(r, 6).Value
            .ReminderSet = True
            ' read appointment values from the worksheet
            On Error Resume Next
            .Start = Cells(r, 1).Value + Cells(r, 7).Value
            .Start = Cells(r, 3).Value + Cells(r, 7).Value
            .Start = Cells(r, 5).Value + Cells(r, 7).Value
            .End = Cells(r, 2).Value + Cells(r, 7).Value
            .End = Cells(r, 4).Value + Cells(r, 7).Value
            .End = Cells(r, 6).Value + Cells(r, 7).Value
            .To = Cells(r, 8).Value
            .Subject = Sheets("Brief").Range("A1")
            .Location = Sheets("Brief").Range("A1")
            .Body = Sheets("Brief").Range("A1")
            .ReminderSet = Cells(r, 9).Value
            ' .Categories = "TestAppointment" ' add this to be able to delete the testappointments
            .ReminderSet = True
            .ReminderMinutesBeforeStart = 0

            On Error GoTo 0
            .Save ' saves the new appointment to the default folder
        End With
        r = r + 1
    Wend
    Set olAppItem = Nothing
    Set olApp = Nothing
End Sub

Sub DeleteTestAppointments()
' deletes all testappointments in Outlook
Dim olApp As Outlook.Application
Dim OLF As Outlook.MAPIFolder
Dim r As Long, dCount As Long
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = GetObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    Set OLF = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
    dCount = 0
    For r = OLF.Items.Count To 1 Step -1
        If TypeName(OLF.Items(r)) = "AppointmentItem" Then
            If InStr(1, OLF.Items(r).Categories, "TestAppointment", vbTextCompare) = 1 Then
                OLF.Items(r).Delete
                dCount = dCount + 1
            End If
        End If
    Next r
    Set olApp = Nothing
    Set OLF = Nothing
End Sub
 

Attachments

  • Automatically Schedule Multiple Outlook Appointments.xlsm
    136 KB · Views: 4
Last edited by a moderator:
A few things.
The ".To" needs to be ".RequiredAttendees"
The ".Save" should be ".Send", otherwise the invite won't actually go out
I also notice you set the Start/End times 3 times...I don't think this is doing what you think it's doing. It's just rewriting the same variable 3 times.
 
@Luke M ,

thanks for following, your modifications are done, but i face this massage, as shown how can i solve.
 

Attachments

  • error.png
    error.png
    12.3 KB · Views: 10
Click "Allow". That's a security feature to prevent malicious macros from sending emails w/o user's knowledge.

You could try to do a work-around by doing
.Display
and then using SendKeys to use the keyboard shortcut to send the email. But using SendKeys can be...buggy.

I'd probably opt for maybe a MsgBox informing user that a dialogue will pop-up asking for their email confirmation, and then doing the .Send
That way the user knows what's going on.
 
this massage appear for all mails that i sent, if i will click allow then I'll click allow more than 100 time and if use display will open more 100 mail box.
there is any way or vba code can handle this issue
 
Dears,

please take a look again to the code that after all modifications, the appointments didn't send and received from the Mail users

Code:
Option Explicit

' requires a reference to the Microsoft Outlook x.0 Object Library
Sub RegisterAppointmentList()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
    DeleteTestAppointments ' deletes previous test appointments
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = CreateObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    r = 3 ' first row with appointment data in the active worksheet
    While Len(Cells(r, 1).Formula) > 0
        Set olAppItem = olApp.CreateItem(olAppointmentItem) ' creates a new appointment
        With olAppItem
            ' set default appointment values
            .Start = Now
            .End = Now
            .Subject = ""
            .Location = ""
            .Body = Cells(r, 6).Value
            .ReminderSet = True
            ' read appointment values from the worksheet
            On Error Resume Next
            .RequiredAttendees = Cells(r, 8).Value
            .Start = Cells(r, 1).Value + Cells(r, 7).Value
            .Start = Cells(r, 3).Value + Cells(r, 7).Value
            .Start = Cells(r, 5).Value + Cells(r, 7).Value
            .End = Cells(r, 2).Value + Cells(r, 7).Value
            .End = Cells(r, 4).Value + Cells(r, 7).Value
            .End = Cells(r, 6).Value + Cells(r, 7).Value
            .To = Cells(r, 8).Value
            .Subject = Sheets("Brief").Range("A1")
            .Location = Sheets("Brief").Range("A1")
            .Body = Sheets("Brief").Range("A1")
            .ReminderSet = Cells(r, 9).Value
            ' .Categories = "TestAppointment" ' add this to be able to delete the testappointments
            .ReminderSet = True
            .ReminderMinutesBeforeStart = 0
 
            On Error GoTo 0
            .Send ' saves the new appointment to the default folder
        End With
        r = r + 1
    Wend
    Set olAppItem = Nothing
    Set olApp = Nothing
End Sub

Sub DeleteTestAppointments()
' deletes all testappointments in Outlook
Dim olApp As Outlook.Application
Dim OLF As Outlook.MAPIFolder
Dim r As Long, dCount As Long
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = GetObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    Set OLF = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
    dCount = 0
    For r = OLF.Items.Count To 1 Step -1
        If TypeName(OLF.Items(r)) = "AppointmentItem" Then
            If InStr(1, OLF.Items(r).Categories, "TestAppointment", vbTextCompare) = 1 Then
                OLF.Items(r).Delete
                dCount = dCount + 1
            End If
        End If
    Next r
    Set olApp = Nothing
    Set OLF = Nothing
End Sub
 
Not exactly sure where you got lost, but implementing the changes I described above, code is working properly for me.
Code:
Option Explicit

' requires a reference to the Microsoft Outlook x.0 Object Library
Sub RegisterAppointmentList()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
    DeleteTestAppointments ' deletes previous test appointments
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = CreateObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    r = 3 ' first row with appointment data in the active worksheet
    While Len(Cells(r, 1).Formula) > 0
        Set olAppItem = olApp.CreateItem(olAppointmentItem) ' creates a new appointment
        With olAppItem
            ' set default appointment values
            .Start = Now
            .End = Now
            .Subject = ""
            .Location = ""
            .Body = Cells(r, 6).Value
            .ReminderSet = True
            ' read appointment values from the worksheet
            On Error Resume Next
            .RequiredAttendees = Cells(r, 8).Value
            .Start = Cells(r, 1).Value + Cells(r, 7).Value 'This line gets overwritten...
            .Start = Cells(r, 3).Value + Cells(r, 7).Value 'by this line which also gets overwritten..
            .Start = Cells(r, 5).Value + Cells(r, 7).Value 'by this line
            .End = Cells(r, 2).Value + Cells(r, 7).Value 'This line gets overwritten...
            .End = Cells(r, 4).Value + Cells(r, 7).Value 'by this line which also gets overwritten..
            .End = Cells(r, 6).Value + Cells(r, 7).Value 'by this line
            .RequiredAttendees = Cells(r, 8).Value  'Changed this
            .Subject = Sheets("Brief").Range("A1")
            .Location = Sheets("Brief").Range("A1")
            .Body = Sheets("Brief").Range("A1")
            .ReminderSet = Cells(r, 9).Value
            ' .Categories = "TestAppointment" ' add this to be able to delete the testappointments
            .ReminderSet = True
            .ReminderMinutesBeforeStart = 0

            On Error GoTo 0
            .Display ' saves the new appointment to the default folder
            Application.Wait (Now + TimeValue("0:00:02"))
            Application.SendKeys "%s"  'Use Send keys method
        End With
        r = r + 1
    Wend
    Set olAppItem = Nothing
    Set olApp = Nothing
End Sub

Sub DeleteTestAppointments()
' deletes all testappointments in Outlook
Dim olApp As Outlook.Application
Dim OLF As Outlook.MAPIFolder
Dim r As Long, dCount As Long
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = GetObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    Set OLF = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
    dCount = 0
    For r = OLF.Items.Count To 1 Step -1
        If TypeName(OLF.Items(r)) = "AppointmentItem" Then
            If InStr(1, OLF.Items(r).Categories, "TestAppointment", vbTextCompare) = 1 Then
                OLF.Items(r).Delete
                dCount = dCount + 1
            End If
        End If
    Next r
    Set olApp = Nothing
    Set OLF = Nothing
End Sub
 
i used it, but the user didn't receive any appointment,

i used another code
but face a error or i can't understand this point from code:

Set Xl = GetObject(, "Excel.Application")
Set Ws = Xl.Workbooks.Parent.Worksheets(Cells(r, 1).Offset(0, 9).Value)
Set xlRn = Ws.Range("MailBodyText")


Code:
Option Explicit
' requires a reference to the Microsoft Outlook x.0 Object Library
Sub RegisterAppointmentList()
' adds a list of appontments to the Calendar in Outlook
    Dim olApp As Outlook.Application
    Dim olAppItem As Outlook.appointmentItem
    Dim r As Long
    Dim myPath As String
 
    Application.ScreenUpdating = False
    myPath = ActiveWorkbook.Path
 
    DeleteTestAppointments    ' deletes previous test appointments
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = CreateObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
 
    r = 10    ' first row with appointment data in the active worksheet
    While Len(Cells(r, 1).Formula) > 0
        Set olAppItem = olApp.CreateItem(olAppointmentItem)    ' creates a new appointment
 
        With olAppItem
            ' set default appointment values
            .Start = Now
            .End = Now
            .Subject = "No subject"
            .Location = ""
            .Body = ""
            .ReminderSet = True
            .MeetingStatus = olMeeting
 
            ' read appointment values from the worksheet
            On Error Resume Next
            .Start = Cells(r, 1).Value + Cells(r, 2).Value
            .End = Cells(r, 1).Value + Cells(r, 3).Value
            .Start = Cells(r, 1).Value + Cells(r, 4).Value
            .End = Cells(r, 1).Value + Cells(r, 5).Value
            .Start = Cells(r, 1).Value + Cells(r, 6).Value
            .End = Cells(r, 1).Value + Cells(r, 7).Value
            .Subject = Cells(r, 8).Value
            .Location = Cells(r, 9).Value
            .ReminderSet = Cells(r, 12).Value
            .Importance = Right(Cells(r, 13).Value, 1)
            .RequiredAttendees = Cells(r, 14).Value
            .Categories = "TestAppointment"    ' add this to be able to delete the testappointments
            .ReminderSet = True
            .ReminderMinutesBeforeStart = 0
 
            On Error GoTo 0
            .Save    ' saves the new appointment to the default folder
        End With
 
        With olApp
            Dim Xl As Excel.Application
            Dim Ws As Excel.Worksheet
            Dim xlRn As Excel.Range
 
            Set Xl = GetObject(, "Excel.Application")
            Set Ws = Xl.Workbooks.Parent.Worksheets(Cells(r, 1).Offset(0, 9).Value)
            Set xlRn = Ws.Range("MailBodyText")
 
 
            Dim varBody As String
            Dim objdata As DataObject
            Dim DataObject As Object
            Set objdata = New DataObject
 
            Application.GoTo Reference:=xlRn
            Selection.Copy
            objdata.GetFromClipboard
            varBody = objdata.GetText
 
            With olAppItem
                .Body = varBody '& vbCrLf & vbCrLf
            End With
        End With
 
        olAppItem.Close olSave
        r = r + 1
        Sheets("scheduleapp").Activate
    Wend
    Set olAppItem = Nothing
    Set olApp = Nothing
    Application.ScreenUpdating = True
End Sub
Sub DeleteTestAppointments()
' deletes all testappointments in Outlook
    Dim olApp As Outlook.Application
    Dim OLF As Outlook.MAPIFolder
    Dim r As Long, dCount As Long
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = GetObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If
    Set OLF = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
    dCount = 0
    For r = OLF.Items.Count To 1 Step -1
        If TypeName(OLF.Items(r)) = "AppointmentItem" Then
            If InStr(1, OLF.Items(r).Categories, "TestAppointment", vbTextCompare) = 1 Then
                OLF.Items(r).Delete
                dCount = dCount + 1
            End If
        End If
    Next r
    Set olApp = Nothing
    Set OLF = Nothing
End Sub
 

Attachments

  • Last Alert.xls
    377 KB · Views: 10
Ah, I see what you mean. It's still being displayed as a single appointment for the user, and not an object to be emailed. Before the Display, add a line with:
Code:
.MeetingStatus = olMeeting 'So the "To" field is visible, and will be emails rather than saved

As for the line of code you posted, it's assinging variables to the Excel application, a Worksheet, and a Range.
 
@Luke M
Done all concerns are handled but it's not finishable :rolleyes:
the mail sent to the first 26 User only :confused: i didn't know Why?
That is very odd. When I run on my machine, it prepares all the emails/memos. I assume you meant that the macro runs all the way, but does not send? Or does it create an error message?
 
So far I can only get the invites to show up on my calendar in Outlook without any Required Atendees attached. Im new to Macros, VBA, ranges, and I tried what you guys mentioned above, but i think I'm missing some steps. If one of you can show me what to do to have the appointment reminders added to Outlook with the Required Attendees attached with he email sent, by recording your screen, then I'll PayPal you $100.
 

Attachments

  • TestExcelappointmentreminder.xls
    84.5 KB · Views: 2
Back
Top