none
Issue with .htmlbody and Outlook 2013 templates RRS feed

  • Question

  • Has anyone encountered this issue?

    We have a number of Outlook templates built both in Office 2010 and later in 2013 which use the usual code that everyone uses to customise the email body for emailing direct from Access databases i.e.

    .HTMLbody = replace(myitem.HTMLbody, "%knownas%", knownas)

    All these templates were working fine until our IT transitioned to MS Exchange 2013 at which point the templates built in Office 2013 failed to work correctly. Those built in Office 2010 still work flawlessly in Office 2013 applications, but if for any reason they are rebuilt and saved as a template in Office 2013, the then fail to work.

    Other sections of code referencing the 2013 templates still works i.e. .to, .sentonbehalfof and .subject all still work but .HTMLbody causes a run-time error.

    Has there been a change to Outlook templates (between 2010 and 2013) which could cause this problem. As stated, this problem only occurred after our transition to MS Exchange 2013. Is there some security aspect that I'm missing here?

    Wednesday, February 11, 2015 8:57 AM

Answers

  • Ok it seems the problem was related to patching. I'm not sure when the last patch came out, but our organisation began to roll out a lot of Office patches in the last 48 hours. After updating and a restart, all of the problems with the code (good or bad) were gone and it's working flawlessly.

    • Marked as answer by Pedrointas Wednesday, February 18, 2015 9:29 AM
    Wednesday, February 18, 2015 9:29 AM

All replies

  • Hello,

    There should be no issues. Could you please be more specific? Did you try to debug the code?

    > templates built in Office 2013 failed to work correctly

    I'd suggest describing the issue in depth. What code exactly do you use? Do you get any errors in the code? If so, what line of code generates an error?

    Wednesday, February 11, 2015 9:25 AM
  • Thanks for the quick reply Eugene. The code is as follows and as you can see it's pretty basic.

    Dim myolapp as new Outlook.Application
    Dim myitem as mailitem
    Dim fname as string
    Dim fqno as string
    
    fname = nz(me.Known_As)
    fqno = Nz(me.Quote_No)
    
    Set myolapp = Outlook.Application
    Set myitem = myolapp.createitemfromtemplate("G:\...\Action Salary Packaging.oft"
    
    myitem.bodyformat = olFormatHTML
    
    With myitem
    .sentonbehalfofname = "Salary.Packaging.help@..."
    .to = Nz(me.logon)
    .htmlbody = Replace(myitem.htmlbody, "%name%", fname)
    .htmlbody = Replace(myitem.htmlbody, "%qno%", fqno)
    .save
    .display
    End with
    
    Set myolapp = nothing
    set myitem = nothing

    At the moment the code always generates an error at the .htmlbody call. If I take those two lines out, the code will run fine inserting the logon into the to field and sent on behalf of from the correct mailbox.

    The main issue was that this was working fine until they upgraded to exchange server 2013 at which point only this template, which was rebuilt in Outlook 2013 because we had to change some of the wording, failed. Any other emails for other databases built in Outlook 2013 will also fail. I've checked the references and they're ok. Like I said, these were working fine until the upgrade.

    In the same module, we use very similar code for two other Outlook templates which were built in Outlook 2010 and have not been amended. They still work and, because they reference the same fields in Access, I can actually change the above code to reference one of the other templates and it works perfectly. It only fails on the 2013 template.

    Regards

    Wednesday, February 11, 2015 10:00 AM
  • I have noticed the following line of code:

    Set myolapp = Outlook.Application

    The code should not work. The variable should be set to the object.

    Anyway, make sure that you set a well-formed HTML markup in the code. Try to set the HTMLBody property to a simple HTML content instead of calling the replace function. Most probably you change the HTML markup incorrectly.

    Wednesday, February 11, 2015 1:04 PM
  • And what is the exact error?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, February 11, 2015 2:21 PM
  • Hi Pedrointas,

    What’s the value of Replace(myitem.htmlbody, "%name%", fname)?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 12, 2015 7:28 AM
    Moderator
  • Ok it seems the problem was related to patching. I'm not sure when the last patch came out, but our organisation began to roll out a lot of Office patches in the last 48 hours. After updating and a restart, all of the problems with the code (good or bad) were gone and it's working flawlessly.

    • Marked as answer by Pedrointas Wednesday, February 18, 2015 9:29 AM
    Wednesday, February 18, 2015 9:29 AM
  • Can anyone tell me that patch which caused this error please - and what needs updating so that it will work again?

    I have a customer on Office 2013 who is experiencing the same problem and I need to  advise his IT team how to fix it.

    Thanks

    Ian

    Wednesday, February 27, 2019 8:54 PM