Help converting code to late binding

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello all,

I have discovered that i'm having problems with a program I developed through manipulating others code and tiredly searching the net for solutions. It works fine in most cases but I have like 5 different people using it and each of them for some reason have different versions of the same excel program. In my search I have discovered that my best bet is to use late binding since it doesn't matter what library reference a person has on their computer. So if anyone can help me figure out how to get this code to go through late binding and ultimately working on all computers. Here is the code:
Code:
Option Explicit


Sub AddToOutlook()


    Dim OL As Outlook.Application
    Dim r As Long, i As Long


    'Checks to see if Outlook is open and either open and closes it or leaves it open
    Dim 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


    'Updates Outlook Calendar
    r = Range("A" & Rows.Count).End(xlUp).Row


    For i = 16 To r
    
        Dim sSubject As String
        Dim sBody As String
        Dim sLocation As String
        Dim Bid As String
        Dim dStartTime As Date, dEndTime As Date
    
        If Range("B" & i).Value <> "" Then
            sSubject = Range("A" & i).Value & " " & ":" & " " & Range("F" & i).Value
            sLocation = Range("G16").Value
        
            If Range("D" & i).Value = "" Then
                dStartTime = Range("C" & i).Value + #5:00:00 PM#
                dEndTime = Range("C" & i).Value + #5:00:00 PM#
            ElseIf Range("D" & i).Value = "EOD" Then
                dStartTime = Range("C" & i).Value + #5:00:00 PM#
                dEndTime = Range("C" & i).Value + #5:00:00 PM#
            Else
                dStartTime = Range("C" & i).Value + Range("D" & i).Value
                dEndTime = Range("C" & i).Value + Range("D" & i).Value
            End If
            
            Bid = Range("A" & i).Value
            sBody = "Bid:" & Bid & vbCrLf & _
                     "Project Name:" & Space(1) & Range("F" & i).Value & vbCrLf & _
                     "Project Discription:" & Space(1) & Range("I" & i).Value & vbCrLf & _
                     "Customer:" & Space(1) & Range("G" & i).Value & vbCrLf & _
                     "Contact Info:" & Space(1) & Range("H" & i).Value




            Dim olAppt As Outlook.AppointmentItem
            Dim olFolder As Outlook.Folder


            Set olFolder = GetPublicFolder("Public Folders\All Public Folders\Projects\Bid Jobs\Bid Schedule")
        
            If Range("B" & i).Value = "U" Then


                Call DeleteAppointments(Bid, olFolder)
            End If
            
            If Not olFolder Is Nothing Then
                Set olAppt = olFolder.Items.Add
                If Not olAppt Is Nothing Then
                    With olAppt
                        .Subject = sSubject
                        .Location = sLocation
                        .Start = dStartTime
                        .End = dEndTime
                        .Body = sBody
                        .Categories = "BID"
                        .ReminderSet = True
                        .MeetingStatus = olMeeting
                        '.RequiredAttendees = "gene@kernsteel.com"
                        .Send
                        .Close olSave
                    End With
                End If
            End If
    
            If bOLOpen = False Then OL.Quit
                Range("B" & i).Value = ""
            End If
    Next i


End Sub

Thanks.

Also does anyone know how to find all the constants because part of it looks at the following function which i need to late bind as well.

Code:
Public Function GetPublicFolder(strFolderPath)
    
    Dim colFolders
    Dim objFolder
    Dim arrFolders
    Dim i
    On Error Resume Next
    strFolderPath = Replace(strFolderPath, "/", "\")
    arrFolders = Split(strFolderPath, "\")
     
    Set objFolder = Application.Session.GetDefaultFolder(18)
    Set objFolder = objFolder.Folders.Item(arrFolders(0))
    If Not objFolder Is Nothing Then
        For i = 1 To UBound(arrFolders)
            Set colFolders = objFolder.Folders
            Set objFolder = Nothing
            Set objFolder = colFolders.Item(arrFolders(i))
            If objFolder Is Nothing Then
                Exit For
            End If
        Next
    End If
    Set GetPublicFolder = objFolder
    Set colFolders = Nothing
     Set ob***p = Nothing
    Set objFolder = Nothing
End Function
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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