none
Outlook Inspector.WordEditor is Nothing RRS feed

  • Question

  • I developed a desktop app in Visual Basic 2010 in which users can send an emailmessage to recipients selected from a list of tennisclub members. This app was created on a Vista machine with Office Professional 2007 (both EN) and has been around for nearly two years. It always worked flawlessly on different user machines. I am now developing on Windows 8.1 Pro + Office Professional Plus 2010 (both NL). Because of some minor database changes I modified the code but did not touch the part where the mailmessage is created and its properties are set. The code that adds an image to the mailitem body all of a sudden throws exceptions. It boils down to the Inspector.Wordeditor returning nothing. I have also a machine with Windows 7 Home Premium + Office Professional Plus 2010 and there I see the same behavior = problem.

    I have seen a lot of similar reports on this and other forums but none really gives me a real solution to my problem. I my app I first check whether Outlook is already active and make sure Word is available. These parts works OK. My code is:

    Imports ol = Microsoft.Office.Interop.Outlook
    Imports wd = Microsoft.Office.Interop.Word

    Dim appOL As Object
    On error Resume Next
    appOL = GetObject(,"Outlook.Application")
    If err.Number <> 0 Then appOL = CreateObject("Outlook.Application")
    On error goto 0
    Err.Clear()

    Dim olItem as ol.MailItem
    Dim olNS as ol.NameSpace
    Dim olDrafts as ol.MAPIFolder
    Dim olExplorer as ol.Explorer
    Dim olInsp as ol.Inspector
    Dim olDoc as wd.Document
    Dim olSel as wd.Selection
    Dim olRecips as ol.Recipients
    Dim olRecip as ol.Recipient

    olNS = appOL.GetNamespace("MAPI")
    olDrafts = olNS.GetDefaultFolder(ol.OlDefaultFolders.olFolderDrafts)
    olExplorer = olDrafts.GetExplorer
    olItem = appOL.CreateItem(ol.OlItemType.olMailItem)
    With olItem
      .To = "..."
      .BCC = "..."
      .Subject = "..."
      .BodyFormat = ol.OlBodyFormat.olFormatHTML
      .Body = "..."
      ...
      ...
      .Display(False) ' Necessary to get the Inspector
      My.Resources.DP_MailHeaderImage.Save("C:\Tmp\DP_MailheaderImage.jpg")
      olInsp = .GetInspector
      If olInsp.IsWordMail = True and olInsp.EditorType = ol.OlEditorType.olEditorWord Then
        olDoc = olInsp.WordEditor
        olDoc.Shapes.AddPicture("C:\Tmp\DP_MailheaderImage.jpg", SaveWithDocument:=True)
        *** AT THIS POINT THE EXCEPTION IS THROWN BECAUSE olDoc = Nothing ***
      End if

    I would appreciate if anyone could throw a light on why this is failing now although it did work previously

    Thks beforehand
    Ruud van der Spoel

     

    • Moved by Amanda Zhu Tuesday, December 31, 2013 3:05 AM better forum
    Monday, December 30, 2013 1:08 PM

Answers

  • Hi guys,

    I thought I had solved my problem but the error came back after a repair run of MS Office 2010, although the reference to the Word 14.0 Object Library remained intact. It appeared that the repair had switched off all Macro's and that's why my app failed again. Allowing Macro's solved it.

    Rgds
    Ruud 

    • Marked as answer by Ruud vd Spoel Monday, January 13, 2014 9:38 AM
    Monday, January 13, 2014 9:38 AM

All replies

  • Hi,

    I am moving this thread to Outlook for Developers forum for better response.

    Best regards,


    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.

    Tuesday, December 31, 2013 3:06 AM
  • Hi,
    I try to reproduce your issue in my side, I test you code in Windows 7 + Office 2010,
    When I run in olDoc = olInsp.WordEditor statement, it return to normal,
     
    Could you see the window of send mail in Outlook when you run this code in your environment?
    I suggest you to add .GetInspector. Activate() before getting the value of WordEditor.
    I just find Ken Slovak’s reply similar with your issue
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/be8dd920-56bd-47b9-851c-3d636f2f37f9/wordeditor-is-null?forum=vsto

    In Outlook  you only get a weak object reference a newly opened Inspector until the first Activate() event fires on that Inspector. A weak object reference will only have a small subset of its properties filled out and valid. Among the properties not valid until that first Activate() are Inspector.WordEditor.
    Regards,


    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.

    Tuesday, December 31, 2013 10:44 AM
  • Hello Ruud vd Spoel,

    Please check out the following points:

    • Did you have a chance to look at the IsWordMail property of the Inspector class? What value does it return?
    • If the IsWordMail and WordEditor properties returns null, it usually indicate that the Activate event is not fired yet and you deal with a weak reference. You have to wait until the Activate event is fired to get the reference.

    Finally, do you have Word installed on the machine?

    Tuesday, December 31, 2013 12:27 PM
  • Thanks for your reaction. Indeed I had read the thread with answer by Ken Slovak. The above code I took from my desktop whereas I had tried Ken's suggestion on my laptop. I just omitted to mention that line of code. To be absolutely sure I tried it again op my desktop so I added the line: olInsp.Activate() just after olInsp=.GetInspector. The Activation is confirmed. When looking at the properties of olInsp I see EditorType=olEditorWord however HTMLEditor=Nothing and WordEditor=Nothing. So Ken's suggestion does not solve the problem.

    The funny thing is that I do see the mail message with everything in it except the image. When running the test from a build executable I can even click on continue when the error pops up then add the image manually in Outlook. I just can't get it to work as I would like. 

    Regards

    Thursday, January 2, 2014 1:02 PM
  • Hello Ruud,

    Please make sure that you have all the latest updates and service packs installed for Office/Outlook.

    Thursday, January 2, 2014 1:06 PM
  • Thanks for this reaction and your previous one. I have set updates to be automatically downloaded and installed which in Win 8.1 works quite well. Office/Outlook Professional Plus 2010 (32bit) is on SP2 MSO (14.0.7106.5003). Win 8.1 Pro is on basic install.
    In reaction to your previous questions: as you can see in my code I get the exception thrown within the 'if ... then' loop where I test for olInsp.IsWorMail=True and olInsp.EditorType=ol.OlEditorType.olEditorWord. So, obviously those conditions are fullfilled. Yet, as replied to Marvin, insp.WordEditor is always returning 'Nothing' even when olInsp.Activate() is inserted. Any further suggestions are apreciated.

    Regards

      
    Friday, January 3, 2014 10:21 AM
  • Hi Ruud,

    I will test the WordEditor property on my PC with Windows 8.1 installed and let you know my results.

    Friday, January 3, 2014 1:08 PM
  • Hi Eugene,

    That's nice of you but I doubt that Windows is the source of the problem since I encounter the same error on my laptop with Windows 7! My feeling is that Outlook 2010 causes the error.  
    In addition to earlier information: I installed Visual Studio 2013 Ultimate with Blend today and tested my app. Same problem.

    Rgds/Ruud  

    Friday, January 3, 2014 5:15 PM
  • Hi everybody,

    For those who follow this thread: using VMWare Workstation I created a Win7 virtual machine and installed Office 2007 and Visual Studio 2013 on it. Then I created a testapp using the exact code as given above including 'olInsp.Activate()'. And as I expected: NO PROBLEM AT ALL!

    It proves to my opinion that Outlook 2010 is the cause of all. Just hope that Microsoft will very quickly submit a patch for this.

    Rgds
    Ruud van der Spoel

    Saturday, January 4, 2014 6:17 PM
  • Hi Ruud,

    To produce a fix, Microsoft developers should reproduce the issue first. I would like to admit that an issue is reproducible only on your machines. Nobody between forum readers and curators couldn't reproduce the issue, including me. Is there any who can reproduce it too???

    That is why I still think that the cause of the issue is related to your environment (installed add-ins, patches, updates and etc.). Of course, I didn't try to run the code on Windows 8.1 yet. But I will do when I finish installing the required software including SDKs and VS2013.

    Sunday, January 5, 2014 2:41 PM
  • Hi Eugene,

    I appreciate the need for MS developers to reproduce the issue. In an effort to dig deeper I installed all important updates offered by Microsoft Update on the Virtual Machine. By accident I gave OK for all of them although I intended to do them step by step (abt 70 updates). There were many security updates for Win7, SQL server 2008, .NET Framework 3.5.1 and Outlook 2007 Junk Email Filter but also updates for MS Office 2007 suites (KB2767916), updates for the 2007 MS Office System (KB967642), an update for MS Office 2013 32-bits edition (KB2817626 - strange because 2013 version was not installed), an update for MS SharePoint Server 2013 Client Components SDK 32-bits edition (KB2817619 - also questionable). After all these updates I tried the app again and ran into the same problem: olInsp.WordEditor = nothing! So I was back to zero. Thereafter I installed MS Office 2007 SP3 and re-tried the app: still the same. Today I upgraded to MS Office Professional Plus (x86 and x64) - Dutch. And now the app works flawlessly again: olInsp.WordEditor nicely indicates 'Microsoft.Office.Word.DocumentClass | {Microsoft.Office.Interop.Word.DocumentClass}'.

    All the tests are done in VS2013 with target framework '.NET Framework 4' and '.NET Framework 4.5.1'

    Of course, it is nice to have found a solution but I can hardly expect my clients to upgrade to MS Office 2013. I am hopeful that with this further info someone is able to reproduce the issue and MS developers will be able to produce a fix.

    Rgds
    Ruud vd Spoel

    Tuesday, January 7, 2014 1:39 PM
  • In addition to what Eugene is asking, it might matter whether or not your Outlook 2010 is a click to run installation or a version installed from an MSI. There are differences in the versions in Outlook 2010, for one thing most COM addins won't run correctly in the online (C2R) versions. It also matters if Word is installed and if so if it's from the same Office installation (SKU) as Outlook is.

    You can also try this code in the Outlook VBA project, it worked here for me in Outlook 2010 on Win 7 and Win 8.1, but the Outlook 2010 versions I used are both MSI installer versions. See if this code in the Outlook VBA project works for you. You will need references in the VBA project to both Outlook and Word:

    Sub testWortdMail()
     Dim appOL As Outlook.Application
     On Error Resume Next
     Set appOL = Application

     Dim olItem As Outlook.MailItem
     Dim olNS As Outlook.NameSpace
     Dim olDrafts As Outlook.MAPIFolder
     Dim olExplorer As Outlook.Explorer
     Dim olInsp As Outlook.Inspector
     Dim olDoc As Word.Document
     Dim olRecips As Outlook.Recipients
     Dim olRecip As Outlook.Recipient

     Set olNS = appOL.GetNamespace("MAPI")
     Set olDrafts = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts)
     Set olExplorer = olDrafts.GetExplorer
     Set olItem = appOL.CreateItem(Outlook.OlItemType.olMailItem)
     With olItem
       .Subject = "test"
       .BodyFormat = Outlook.OlBodyFormat.olFormatHTML
       .Body = "this is a test"
       '.Display (False) ' Necessary to get the Inspector
       'My.Resources.DP_MailHeaderImage.Save ("C:\Tmp\DP_MailheaderImage.jpg")
       Set olInsp = .GetInspector
       If olInsp.IsWordMail = True And olInsp.EditorType = Outlook.OlEditorType.olEditorWord Then
         Set olDoc = olInsp.WordEditor
         Debug.Print (olDoc Is Nothing)
       End If
     End With
    End Sub

    When I run this code I get a printout of "False", indicating that the Document object is not Nothing.


    Ken Slovak MVP - Outlook

    Tuesday, January 7, 2014 3:43 PM
    Moderator
  • Hi Ken,

    On both my desktop (Win 8.1) and laptop (Win 7) I installed Office Professional Plus 2010 version 14.0.7106.5003. On the desktop the 32-bits version and on the laptop the 64-bits version. The installs include all the Office components so besides Outlook also Excel, Word, Access, Publisher, etc. On the two machines at present Outlook is on version 14.0.7109.5000 SP2 MSO. For the installation I used two different files downloaded from Microsoft Technet. On the desktop 'nl_office_professional_plus_2010_x86_516179.exe' and on the laptop 'nl_office_professional_plus_2010_x64_517268.exe'.

    I ran your above code in Excel VBA and it returned TRUE!

    Anymore idea's or suggestions?

    Thks / Rgds
    Ruud

    Tuesday, January 7, 2014 10:27 PM
  • Please run the code in the Outlook VBA application as I asked. It was set up for running from there.

    I have Office 2010 from different sources than TechNet, I'm not familiar with those file names. But the version you have is what I'm running on Office 2010 machines here.


    Ken Slovak MVP - Outlook

    Tuesday, January 7, 2014 10:43 PM
    Moderator
  • Hi Ruud,

    Did you try to open the support case at http://support.microsoft.com/contactus/?ws=support&SegNo=1#livehelp_contact?

    If it's an actual bug there wouldn't be any charge for support. But if this is not a bug, you may be charged depending on your support level.

    Wednesday, January 8, 2014 12:42 PM
  • Hi Ken,

    Sorry for my mistake! This time I ran your code in Outlook VBA. And guess what ... it returned FALSE. There is something strange which I cannot explain but is important to know for those who encounter the same problem:
    1. On my Win 8.1 desktop in Outlook 2010 initially there was no reference to the Microsoft Word 14.0 Object Library. Once this was corrected your code and my app worked as required! Yet I have not ever encountered a problem in Outlook without this reference. Evidently Outlook 2010 can function well without it.

    2. On my Win 7 laptop in Outlook there was a reference to the Word Library but I also found some code in the Project1 (VBAProject.OTM) under ThisOutlookSession which will give you a warning if the Word Reference is missing. Most certainly this is not my code but I guess it came with one of the updates. I don't remember but I guess I must have seen the warning in an early stage and corrected this.

    In any case with this reference properly set within Outlook VBA and saving the VBA code when closing Outlook the problem I had will be fixed.

    I thank you and Eugene very much for helping me into the right direction.

    Regards
    Ruud van der Spoel

    • Marked as answer by Ruud vd Spoel Thursday, January 9, 2014 10:02 AM
    • Unmarked as answer by Ruud vd Spoel Monday, January 13, 2014 9:18 AM
    Thursday, January 9, 2014 10:02 AM
  • Hi guys,

    I thought I had solved my problem but the error came back after a repair run of MS Office 2010, although the reference to the Word 14.0 Object Library remained intact. It appeared that the repair had switched off all Macro's and that's why my app failed again. Allowing Macro's solved it.

    Rgds
    Ruud 

    • Marked as answer by Ruud vd Spoel Monday, January 13, 2014 9:38 AM
    Monday, January 13, 2014 9:38 AM
  • .GetInspector. Activate() saved my day! Thank you very much.

    Friday, June 8, 2018 7:45 AM