【问题标题】:Getinspector in Sending Outlook appointment invitation through shared folder with VBAGetinspector 在使用 VBA 通过共享文件夹发送 Outlook 约会邀请
【发布时间】:2016-06-29 05:26:13
【问题描述】:

尊敬的 Stackoverflow 社区,

如您所见,我是这个论坛的新手。最近,我一直在通过互联网论坛的指南学习 VBA。大多数时候,stackoverflow 中可用的问答确实帮助我解决了我的挑战。但是,我有这个直到现在我找不到解决方案和原因。

我的目标是通过共享文件夹发送 Outlook 约会,并使用 getinspector 将格式化的单元格包含从 excel 工作簿复制到创建的 Outlook 约会。如果我分别完成每项任务,一切都会很好。当我集成代码时,getinspector 似乎不再工作了。以下是我使用的代码(如果代码看起来不专业,请原谅我,因为我一直在论坛的帮助下自己学习 VBA):

Sub VBA_Appointment()

Dim objOL   As outlook.Application
Dim objAppt As outlook.AppointmentItem
Dim objFolder As Object
Dim objRecip As outlook.recipient
Dim strName As String
Dim wrdrng As Word.Range
Dim Doc As Word.document

Application.ScreenUpdating = False
Application.EnableEvents = False

Const olAppointmentItem = 1
Const olFolderCalender = 9

Set objOL = CreateObject("Outlook.Application")
Set objAppt = objOL.CreateItem(olAppointmentItem)
Set Doc = objAppt.GetInspector.WordEditor
Set objNS = objOL.Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders

strName = "John Smith"

Set objRecip = objNS.CreateRecipient(strName)
Set objFolder = objNS.GetsharedDefaultFolder(objRecip, olFolderCalender)

With objAppt
.Subject = "Testing"
.MeetingStatus = 1
.RequiredAttendees = ""
.Start = Now
.Location = ""
.BusyStatus = 1 '0=free;1=Tentative;2=Busy
'Copy desired data from EXCEL sheet and paste on the opened OUTLOOK Appointment
ThisWorkbook.Sheets("Sheet1").Range("A1:B50").Copy
Set wrdrng = Doc.Range
.Display
wrdrng.Paste
Application.CutCopyMode = False
End With

Application.EnableEvents = True
Application.ScreenUpdating = True

Set objAppt = Nothing
Set objOL = Nothing
Set objNS = Nothing
Set objFolder = Nothing
Set objRecip = Nothing

End Function

因此,如果有人 VBA 专业人士可以指出原因并解释从剪贴板粘贴的原因(最后一步)在这种情况下不起作用,我将不胜感激。

非常感谢。

干杯

【问题讨论】:

    标签: vba excel outlook


    【解决方案1】:

    代码对我有用,但可能是因为可用内存、处理器速度等 - 因为你是从 excel 复制到另一个应用程序 - 我在 PowerPoint 中遇到了类似的情况,我会使用这种方法(它可以sleep 更好,因为它以毫秒为单位,完全取决于您的流程以及最适合您的方法)

    ...
    ThisWorkbook.Sheets("Sheet1").Range("A1:B50").Copy
    Application.Wait Now + TimeValue("00:00:01")
    Set wrdrng = Doc.Range
    .Display
    'if it doesn't work above, paste it here (both would be too much time and not really needed)
    Application.Wait Now + TimeValue("00:00:01")
    wrdrng.Paste
    Application.CutCopyMode = False
    End With
    ...
    

    【讨论】:

    • 对你的建议很有帮助。我很欣赏这一点。 VBA 代码有效。 =)
    猜你喜欢
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2017-10-27
    • 2018-04-09
    • 1970-01-01
    • 2011-03-22
    相关资源
    最近更新 更多