Changes to meeting body not properly saving

Status
Not open for further replies.

erichamion

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
I'm trying to create an appointment from a template, then make specific substitutions throughout the subject, location, and body of the appointment. The body substitutions are done with the WordEditor because I need to preserve formatting. It's almost working, but there's a quirk I can't figure out. Any help would be greatly appreciated.

The appointment is created, and the substitutions appear to work, but I then actually need to save changes through the user interface in order for the body substitutions to remain. When I open the appointment for the first time and then close it with the red "X", I'm prompted whether to save changes. If I choose "No", then the subject and location remain correct, but the appointment body reverts back to the template. If I move the meeting to a different time before ever opening it, then the body reverts without any prompt (although, again, the subject and location keep their substitutions).

I can work around the first issue easily by always saving changes or using the "Save and Close" button. The second issue (yes, it's really just a different aspect of the same issue) is a big problem because these appointments do typically get moved around. If I'm careless and don't open the appointment first, then it's lost.

Could somebody please help with identifying what I'm missing? Thank you.

This is using Outlook 2013, and the calendar is on an Exchange server. The script below requires a reference to the Word object library, and templatePath should be changed to the location of a meeting template that has one or more of the strings "<<~Foo~>>", "<<~Bar~>>", and "<<~Baz~>>" in both the subject and the body.

Code:
Option Explicit 
 
Sub calTest() 
    Dim fields As Collection 
    Const templatePath As String = "E:\Example.oft" 
  
   Set fields = getFieldsTest() 
  
   fillTemplateTest fields, templatePath 
End Sub 
 
Sub fillTemplateTest(fields As Collection, templatePath As String) 
    Dim objAppointment As Outlook.AppointmentItem 
    Dim appointmentDoc As Word.Document 
    Dim subject As String 
    'Dim location As String 
    Dim baseIndex As Long 
    Dim indexOne As Long 
    Dim indexTwo As Long 
    Dim matchStr As String 
    Dim replStr As String 
    Dim textRange As Range 
    Dim fullText As String 
    Dim objFind As Word.Find 
 
  Set objAppointment = Application.CreateItemFromTemplate(templatePath) 
    objAppointment.Start = Now 
    objAppointment.End = DateAdd("n", 30, Now) 
  
   subject = objAppointment.subject 
    indexOne = InStr(subject, "<<~") 
    Do While indexOne > 0 
        indexTwo = InStr(indexOne, subject, "~>>") 
        If indexTwo > indexOne Then 
            matchStr = Mid(subject, indexOne, indexTwo - indexOne + 3) 
            replStr = "" 
            On Error Resume Next 
            replStr = fields.Item(Mid(matchStr, 4, Len(matchStr) - 6)) 
            On Error GoTo 0 
            subject = Replace(subject, matchStr, replStr) 
          
           indexOne = indexOne - 1 
        End If 
      
       indexOne = InStr(indexOne + 1, subject, "<<~") 
    Loop 
    objAppointment.subject = subject 
  
   'Repeat the above block using objAppointment.location 
    'Removed from example as unnecessary.  Modifying location 
    'works just as well as modifying subject. 
  
   'Adding the line below so that we save before getting the WordEditor 
    '(and still save again later on) made no difference 
    'objAppointment.Save 
  
   Set appointmentDoc = objAppointment.GetInspector.WordEditor 
    Set textRange = appointmentDoc.Range 
    fullText = textRange.Text 
    indexOne = InStr(fullText, "<<~") 
    Do While indexOne > 0 
        indexTwo = InStr(indexOne, fullText, "~>>") 
        If indexTwo > indexOne Then 
            Set objFind = textRange.Find 
            objFind.Text = Mid(fullText, indexOne, indexTwo - indexOne + 3) 
            replStr = " " 
            On Error Resume Next 
            replStr = fields.Item(Mid(objFind.Text, 4, Len(objFind.Text) - 6)) 
            On Error GoTo 0 
            If objFind.Execute Then 
                textRange.Text = replStr 
                indexOne = baseIndex 
            Else 
                baseIndex = indexOne 
            End If 
          
           Set textRange = appointmentDoc.Range 
            fullText = textRange.Text 
        End If 
      
       indexOne = InStr(indexOne + 1, fullText, "<<~") 
    Loop 
  
   objAppointment.Save 
    Set objAppointment = Nothing 
  
   'Adding the line below immediately discards all changes to the 
    'appointment body. 
    'appointmentDoc.Close 
  
   'Adding the line below prompts the user for a location 
    'to save a file, which is not what we want. 
    'appointmentDoc.Save 
    Set appointmentDoc = Nothing 
   
 
End Sub 
 
Function getFieldsTest() As Collection 
    Dim RetVal As Collection 
  
   Set RetVal = New Collection 
    RetVal.Add Item:="Pike", key:="Foo" 
    RetVal.Add Item:="Kirk", key:="Bar" 
    RetVal.Add Item:="Picard", key:="Baz" 
  
   Set getFieldsTest = RetVal 
    Set RetVal = Nothing 
End Function
 
Well, the appointment isn't visible on the calendar until it's saved, so I wouldn't say it's doing nothing. But you're right, it's not saving the changes to the body.

Since posting, I've found that if I display and close the appointment through VBA, the changes are saved. It also works as expected if I just use objAppointment.Body for text replacement (but it kills the formatting, of course). So it will work by replacing objAppointment.Save with either:
objAppointment.Display
objAppointment.Save
objAppointment.Close olDiscard​
Or just:
objAppointment.Display
objAppointment.Close olSave
That works, although I'm not fond of the flickering windows. This is typically being called several times in a row to create three or four appointments, so the flickering would be a nuisance.

It seems like the appointment's Word document isn't really syncing up with the actual appointment until it's shown somehow. Is there a good way around this, or is flickering windows the best solution?

Thank you very much, Diane.
 
i will see what i can find out -
 
Aha! I found the answer at http://social.msdn.microsoft.com/Fo...nging-getinspectorwordeditor?forum=outlookdev. If I replace objAppointment.Save with:
Set objPages = objAppointment.GetInspector.ModifiedFormPages
objPages.Add "General"
objAppointment.GetInspector.HideFormPage "General"
objAppointment.Close olSave

(with "Dim objPages as Outlook.Pages" earlier), it works without trying to open any windows. I'm pretty inexperienced at this and have never worked with form pages. I don't really know what this is doing or why it works, but it works.

Thank you.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C Disabling "Do you want to save changes?" Meeting Popup? Using Outlook 0
B Outlook Calendar - Time zone changes after the meeting request is accepted. Using Outlook 1
S Meeting changes Using Outlook 1
S Appointment font size when printing only changes Tasks' font Using Outlook 0
V Latest Changes to form not appearing for some users Outlook VBA and Custom Forms 3
T How to deal with Upcoming GMAIL changes Using Outlook 2
O Unable to make changes to an existing Calendar entry Using Outlook 11
C Tracking Calendar Changes? Using Outlook 1
P Outlook 2019 UI changes after 20H2 update Using Outlook 1
D Prevent popup of "Do you want to save changes?" when closing after opening an appointment to view Outlook VBA and Custom Forms 2
A Form style totally changes Outlook VBA and Custom Forms 2
P OWA Settings->Calendar->Events from Email; Setting changes do not hold Using Outlook 1
W Message class changes of a custom form changes to the default form Using Outlook 2
D Outlook Message Window Changes Size and Position Using Outlook 1
T Outlook changes default account Using Outlook 1
P Account Changes Using Outlook 4
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
M Spell Checker Changes -- Not as Predictive as Previously Using Outlook 3
C Outlook - cannot save subject line changes Using Outlook 2
T Incoming Mail Changes Fonts Using Outlook 0
Cdub27 Your changes to this item couldn't be saved because Server Denied Operation (HTTP 403 Forbidden) Using Outlook 1
M receive mail when appointment category changes and create task from appointment Outlook VBA and Custom Forms 0
Mark Foley Outlook prompts for IMAP user/PW when domain PW changes Using Outlook 0
K outlook 2010 changes text tab position when sending Using Outlook 2
G Outlook 2013 not syncing changes to outlook.com account calendar? Using Outlook.com accounts in Outlook 8
M Display as name in outlook contacts changes Using Outlook 5
D Outlook 2010/IMAP - Restoring from system tray changes to unused ibox.... Using Outlook 1
H "Normal" Style Changes When Replying Using Outlook 4
D Connecting to Exchange changes calendar functionality Exchange Server Administration 1
airtas oft templates not sending changes Using Outlook 2
T outlook cal for mac changes times of recurring meetings on its own Using Outlook 1
james27_84 Outlook 2013 not synching changes to server Using Outlook 6
J Local Outlook 2013 folder and message changes not synced with EAS to Outlook.com Using Outlook.com accounts in Outlook 7
R People View Changes during search Using Outlook 2
C Reports always ask 'Would you like to save your changes?' BCM (Business Contact Manager) 1
T The Formatting Changes When A Recurring Appointment is Changed Using Outlook 1
Hudas Outlook VBA script reverting back to previous changes Outlook VBA and Custom Forms 2
D Monitor any changes to a sub-folder Outlook VBA and Custom Forms 4
E Outlook prompts to save attachments when no changes have been made. Using Outlook 0
E Saving Changes To Edited E-Mail Received Message Using Outlook 0
B Contact changes from Personal to Shared when opening custom form Using Outlook 0
X Outlook 2007+ Changing signature also changes subject? Using Outlook 9
C Dates changes to 1899 when Tab key hit in Time... Using Outlook 3
J From column changes when message is read Using Outlook 1
B 2003 >> 2010 outlook today security changes (Iframes? Href?) Using Outlook 1
A Problem syncing any changes to appointment times on PDAs ... Using Outlook 11
E Signature changes font of last line of template Using Outlook 18
D Quick Parts - font changes Using Outlook 6
D Quick Parts - font changes Using Outlook 0
D Outlook 2007 Reminder Times Change When User Changes Time Zone in Date/Time Using Outlook 4

Similar threads

Back
Top