Hello all. Here is my situation, i am trying to link excel with outlook. I've been able to get it to pretty much do what I want it to do but i'm having problems with one area. Column D in my spreadsheet holds the date of each project is due and Column E holds the time at which each project is due. Now column has three possibilites, blank, filled, or EOD (END OF DAY). The following is my code with the problem area in red.
As you can see the start and end date are on column D. and when i set it too that then i get an entry of start and end date being ok but start and end time being 12:00 am. How do i get the info from column E to change it so that time either shows what is in column E or 5:00 PM which is the end of the work day here.
Rich (BB code):
Option Explicit
Sub AddToOutlook()
Dim OL As Outlook.Application
Dim olAppt As Outlook.AppointmentItem
Dim NS As Outlook.Namespace
Dim colItems As Outlook.Items
Dim olApptSearch As Outlook.AppointmentItem
Dim r As Long, i As Long, sSubject As String, sBody As String, sLocation As String
Dim dStartTime As Date, dEndTime As Date
Dim sSearch As String, bOLOpen As Boolean
On Error Resume Next
Set OL = GetObject(, "Outlook.Application")
bOLOpen = True
If OL Is Nothing Then
Set OL = CreateObject("Outlook.Application")
bOLOpen = False
End If
Set NS = OL.GetNamespace("MAPI")
Set colItems = NS.GetDefaultFolder(olFolderCalendar).Items
r = Range("B" & Rows.Count).End(xlUp).Row
For i = 16 To r
If Range("B" & i).Value = "X" Then
sSubject = Range("A" & i).Value & " " & ":" & " " & Range("G" & i).Value
sBody = ""
sLocation = Range("H16").Value
'Problem Area
If Range("E" & i).Value = "" Then
dStartTime = Range("D" & i).Value & "5:00PM"
dEndTime = Range("D" & i).Value & "5.00PM"
ElseIf Range("E" & i).Value = "EOD" Then
dStartTime = Range("D" & i).Value & "5:00PM"
dEndTime = Range("D" & i).Value & "5.00PM"
Else
dStartTime = Range("D" & i).Value & Range("E" & i).Value
dEndTime = Range("D" & i).Value & Range("E" & i).Value
End If
If olApptSearch Is Nothing Then
Set olAppt = OL.CreateItem(olAppointmentItem)
olAppt.Body = sBody
olAppt.Subject = sSubject
olAppt.Location = sLocation
olAppt.Start = dStartTime
olAppt.End = dEndTime
olAppt.Categories = "BID"
olAppt.Close olSave
End If
If bOLOpen = False Then OL.Quit
Range("B" & i).Value = " "
End If
Next i
End Sub
As you can see the start and end date are on column D. and when i set it too that then i get an entry of start and end date being ok but start and end time being 12:00 am. How do i get the info from column E to change it so that time either shows what is in column E or 5:00 PM which is the end of the work day here.