dkoester77
12-14-2016, 04:08 PM
Here's the use case: User copies text/tables from a webpage, then creates an appointment on a shared calendar with information pasted into the body. Pasted text needs to retain formatting. I found a script that creates the appointment with the pasted text, but only works with personal calendar. I found another that creates the shared calendar appointment, but won't paste the text. When I combined them (or attempted to) I found that both scripts have "Set objAppt = ..." with different properties. As you'd expect, if I remove either of them, the code does half of what it's supposed too. This is obviously the problem, but the solution is not so obvious to me!
If someone could point me in the right direction, I would really appreciate it. I'm good at copy/pasting, but definately not a coder...
-Doug
Sub CreateAppt()
Dim objAppt As Outlook.AppointmentItem
Dim objWord As Word.Application
Dim objInsp As Inspector
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objDummy As Outlook.MailItem
Dim objRecip As Outlook.Recipient
Dim strMsg As String
Dim strName As String
On Error Resume Next
strName = "Troy-PublicSafetyDemo"
Set objAppt = Application.CreateItem(olAppointmentItem)
Set objInsp = objAppt.GetInspector
Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objDummy = objApp.CreateItem(olMailItem)
Set objRecip = objDummy.Recipients.Add(strName)
On Error Resume Next
Set objFolder = _
objNS.GetSharedDefaultFolder(objRecip, _
olFolderCalendar)
Set objAppt = objFolder.Items.Add
With objAppt
.Subject = "??- TENTATIVE"
.Start = Date
.AllDayEvent = True
.ReminderSet = False
.BusyStatus = olBusy
objSel.PasteAndFormat (wdFormatOriginalFormatting)
.Display
End With
Set objApp = Nothing
Set objNS = Nothing
Set objFolder = Nothing
Set objDummy = Nothing
Set objRecip = Nothing
Set objAppt = Nothing
Set objSel = Nothing
Set objInsp = Nothing
Set objWord = Nothing
End Sub
If someone could point me in the right direction, I would really appreciate it. I'm good at copy/pasting, but definately not a coder...
-Doug
Sub CreateAppt()
Dim objAppt As Outlook.AppointmentItem
Dim objWord As Word.Application
Dim objInsp As Inspector
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objDummy As Outlook.MailItem
Dim objRecip As Outlook.Recipient
Dim strMsg As String
Dim strName As String
On Error Resume Next
strName = "Troy-PublicSafetyDemo"
Set objAppt = Application.CreateItem(olAppointmentItem)
Set objInsp = objAppt.GetInspector
Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objDummy = objApp.CreateItem(olMailItem)
Set objRecip = objDummy.Recipients.Add(strName)
On Error Resume Next
Set objFolder = _
objNS.GetSharedDefaultFolder(objRecip, _
olFolderCalendar)
Set objAppt = objFolder.Items.Add
With objAppt
.Subject = "??- TENTATIVE"
.Start = Date
.AllDayEvent = True
.ReminderSet = False
.BusyStatus = olBusy
objSel.PasteAndFormat (wdFormatOriginalFormatting)
.Display
End With
Set objApp = Nothing
Set objNS = Nothing
Set objFolder = Nothing
Set objDummy = Nothing
Set objRecip = Nothing
Set objAppt = Nothing
Set objSel = Nothing
Set objInsp = Nothing
Set objWord = Nothing
End Sub