正确的后期绑定非版本特定的Excel VBA代码

我有一个Excel电子表格,我的VBA代码从共享日历上创buildOutlook约会。 它将由多个项目经理操作(当然不是同一时间)。 我碰到的问题是与多个用户,我发现有一对夫妇正在使用和旧版本的Office,因此我已经了解到,我应该使用“后期绑定”,我想使这与旧版本更兼容。

我似乎无法find任何有关如何将我有迟到绑定的信息,以及我必须创build此代码的所有示例都是早期绑定的。 我可以得到一些关于转换的帮助吗? 我有2个其他模块,我也必须转换,但将是相同的线。

Option Explicit Sub SCHMTG() 'Schedule Meeting Dim wb As Workbook Set wb = ThisWorkbook Dim ws As Worksheet Set ws = wb.Sheets("Projects") ws.Unprotect "" Dim check As Boolean check = False Dim o As Outlook.Application Set o = New Outlook.Application Dim oNS As Outlook.Namespace Set oNS = o.GetNamespace("MAPI") Dim FOL As Outlook.MAPIFolder Set FOL = oNS.GetFolderFromID("00000000F4EFC638C1F878469E872F63F51D794A0100F96BCFC3DAF87B4F8C66193C3EA6F4F40000029DA2430000") Dim oAPT As Outlook.AppointmentItem Dim oAPT_DATE As Date Dim oAPT_TIME As Date Dim oOBJECT As Object Dim b As CheckBox Dim r As Integer Dim c As Integer Set b = ws.CheckBoxes(Application.Caller) With b.TopLeftCell r = .Row c = .Column End With For Each oAPT In FOL.Items 'Search for existing meeting oAPT_DATE = Format(oAPT.Start, "MM-DD-YYYY") oAPT_TIME = TimeValue(oAPT.Start) If oAPT_DATE = ws.Cells(r, c - 3).Value And oAPT.Subject = ws.Cells(r, 1).Value And oAPT_TIME = ws.Cells(r, c - 2).Value Then check = True Else End If Next oAPT If check = False Then 'If no meeting already exist Then create new meeting Set oAPT = FOL.Items.Add(olAppointmentItem) With oAPT .Start = ws.Cells(r, c - 3).Value + ws.Cells(r, c - 2).Value .Duration = ws.Cells(r, c - 1).Value * 60 .Subject = ws.Cells(r, 1).Value & " " & ws.Cells(1, c).Value .Body = "Project: " & ws.Cells(r, 1).Value & vbCrLf & "Location: " & ws.Cells(r, 2) & vbCrLf & "OASIS#: " & ws.Cells(r, 3) & vbCrLf & "Project Manager: " & ws.Cells(r, 5) & vbCrLf & "Distributor: " & ws.Cells(r, 8) & vbCrLf & "Assigned Technitian: " & ws.Cells(r, c - 5) & vbCrLf & "Date: " & ws.Cells(r, c - 3) & vbCrLf & "Start Time: " & Format(ws.Cells(r, c - 2), "h:mm am/pm") & vbCrLf & "Duration: " & ws.Cells(r, c - 1) & " Hour(s)" .Location = ws.Cells(r, 2).Value .Recipients.Add Cells(r, c - 4).Value .MeetingStatus = olMeeting .ReminderMinutesBeforeStart = 1440 .Save .Send End With ws.Cells(r, c - 1).Locked = True ws.Cells(r, c - 2).Locked = True ws.Cells(r, c - 3).Locked = True ws.Cells(r, c - 5).Locked = True Else End If ws.Cells(r, 1).Locked = True ws.Cells(r, 2).Locked = True ws.Cells(r, 3).Locked = True ws.Protect "", True, True End Sub 

删除任何VBA项目引用到Outlook库。

将任何Outlook对象声明As Object而不是使用Outlook库types名称。 使用CreateObject()代替New

例如:

 Dim oAPT As Outlook.AppointmentItem Dim o As Outlook.Application Set o = New Outlook.Application 

将会

 Dim oAPT As Object Dim o As Object Set o = CreateObject("Outlook.Application") 

任何Outlook派生的常量(如olAppointmentItem都应该在您的代码中声明为常量,或者replace为其数值(您可以使用对象浏览器find)