WarPigl3t
Well-known Member
- Joined
- May 25, 2014
- Messages
- 1,611
Hi. I am doing a job for someone. I got most of this code online, but I made some changes to it. The original code doesn't work and neither does this new code that I made. I was hoping someone could help me out. Each row is going to be a new calendar appointment in Outlook. I also want to know how to make it into a meeting instead of an appointment. The code I wrote is self explanatory but the code I didn't write is hard to understand. Help me troubleshoot the code and explain what the lines I highlighted in red are. No rush. Need to figure it out by Saturday. You don't even have to write the code for me. I can figure it out if someone explains the red highlighted areas. Thanks.
<tbody>
</tbody>
A | B | C | D | E | F | G | H | |
1 | Sequence | Subject | Location | Description | Date | Start Time | End Time | Attendees |
2 | 1001 | Test 1 | Location 1 | Description 1 | 9/28/2016 | 9:00 PM | 9:15 PM | sean@seangirvan.com;sean.girvan@utegration.com |
3 | 1002 | Test 2 | Location 2 | Description 2 | 9/28/2016 | 9:15 PM | 9:30 PM | sean@seangirvan.com;sean.girvan@utegration.com |
4 | 1003 | Test 3 | Location 3 | Description 3 | 9/28/2016 | 9:30 PM | 9:45 PM | sean@seangirvan.com;sean.girvan@utegration.com |
5 | 1004 | Test 4 | Location 4 | Description 4 | 9/28/2016 | 9:45 PM | 10:00 PM | sean@seangirvan.com;sean.girvan@utegration.com |
6 | 1005 | Test 5 | Location 5 | Description 5 | 9/28/2016 | 10:00 PM | 10:15 PM | sean@seangirvan.com;sean.girvan@utegration.com |
<tbody>
</tbody>
Code:
Const firstRow_withData = 2
Const sequenceColumn = 1
Const subjectColumn = 2
Const locationColumn = 3
Const descriptionColumn = 4
Const dateColumn = 5
Const startTimeColumn = 6
Const endTimeColumn = 7
Const attendeesColumn = 8
Sub RegisterAppointmentList()
[COLOR=#008000] 'adds a list of appontments to the Calendar in Outlook[/COLOR]
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
On Error Resume Next
[COLOR=#008000] 'Worksheets("Schedule").Activate 'unnecessary[/COLOR]
Set olApp =[COLOR=#ff0000] GetObject("", "Outlook.Application")[/COLOR]
On Error GoTo 0
If olApp [COLOR=#ff0000]Is Nothing[/COLOR] 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 = firstRow_withData [COLOR=#008000]'first row with appointment data in the active worksheet[/COLOR]
Dim mysub, myStart, myEnd
lastRow = Cells(Rows.Count, sequenceColumn).End(xlUp).Row
Do Until r > lastRow
mysub = Cells(r, locationColumn) & ", " & Cells(r, descriptionColumn)
myStart = DateValue(Cells(r, dateColumn).Value) + Cells(r, startTimeColumn).Value
myEnd = DateValue(Cells(r, dateColumn).Value) + Cells(r, endTimeColumn).Value
[COLOR=#008000]'DeleteTestAppointments mysub, myStart, myEnd '??? No idea what this is[/COLOR]
Set olAppItem = olApp.CreateItem(olAppointmentItem) [COLOR=#008000]'creates a new appointment[/COLOR]
With olAppItem
[COLOR=#008000]'set default appointment values[/COLOR]
[COLOR=#008000]'[/COLOR][COLOR=#ff0000].Location[/COLOR][COLOR=#008000] = Cells(r, locationColumn) 'Error here[/COLOR]
.Body = ""
.[COLOR=#ff0000]ReminderSet [/COLOR]= True
.[COLOR=#ff0000]BusyStatus = olFree[/COLOR]
'.RequiredAttendees = "johndoe@microsoft.com"
On Error Resume Next
.Start = myStart
.End = myEnd
.Subject = Cells(r, subjectColumn) & ", " & .Location
.[COLOR=#ff0000]Attachments.Add ("c:\temp\somefile.msg")[/COLOR]
.Location = Cells(r, locationColumn).Value
.Body = .Subject & ", " & Cells(r, dateColumn).Value
.ReminderSet = True
.[COLOR=#ff0000]BusyStatus = olBusy[/COLOR]
.[COLOR=#ff0000]Categories = "Orange Category[/COLOR]" [COLOR=#008000]'add this to be able to delete the testappointments[/COLOR]
On Error GoTo 0
.Save [COLOR=#008000]'saves the new appointment to the default folder[/COLOR]
End With
r = r + 1
Loop
Set olAppItem = Nothing
Set olApp = Nothing
MsgBox "Done !"
End Sub
Last edited: