【发布时间】:2017-11-13 22:08:10
【问题描述】:
我有一个 Excel 电子表格,我的 VBA 代码可以从中提取,以便在共享的 Outlook 日历上创建约会。它将由多个项目经理(当然不是同时)操作。
我发现一些用户拥有旧版本的 Office,因此我了解到我应该使用“后期绑定”来使其与旧版本兼容。
如何将我拥有的内容转换为后期绑定。我必须创建此代码的所有示例都是早期绑定。
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
【问题讨论】:
-
我也在使用 Excel 2016,我在 2015 年有一个用户,在 2010 年有一个用户
标签: excel vba outlook late-binding