Error reading Outlook HTML Body

Error reading Outlook HTML Body

I’m getting error 438 : object doesn't support this property or methodwhen I am trying to run the macro on a new machine:

error 438 : object doesn't support this property or method

Set HTMLdoc = New MSHTML.HTMLDocument
With HTMLdoc
.body.innerHTML = OutlookMail.HTMLBody **'******** Error Line**
Set tables = .getElementsByTagName("table")
End With

There is apparently such thing as a text to code ratio for SO. Your not quite Minimal, Complete, and Verifiable example, though minimal, could do with more text explanation. What have you tried? And this worked on a prior machine did it? What are the differences between machines? How is OutlookMail declared and set? I have also formatted your code correctly.
– QHarr
Jul 3 at 7:39

This may be because of the references, have you check that you setup the same refenrence s in the visual basic editor?
– IRENE G
Jul 3 at 7:40

@QHarr I’m not sure why the Text-to-Code ratio only prevents posting of the question certain times… but it prevents questions from being posted with more than (I think) 3:1 text to code ratio… however in this case the lengthy title might help. I’ll ask Sam. 🙂
– ashleedawg
Jul 3 at 7:47

2 Answers
2

Yes it is working fine in my system. But when I tried to install this in new system, it creates this error.

No changes in the code, I am running the same excel macro file on some outllok mails.
Even the outlook mails which I used for testing, i am using the same files in the new machine.

Also, the Tool>>Reference libraries, I have checked all the Items like MS HTML object library, MS Outlook 16.0 Object library and other default checkboxes are maintained same in the system.

The code abruptly breaks when it reaches this line :
. Body. Innerhtml = Outlookmail. HTMLBody

.body.innerHTML = OutlookMail.HTMLBody

The inner HTML markup of the body doesn’t equal to the HTML markup of the Outlook’s message body. It includes other outer html markup that should be removed before.

Anyway, VBA macros are not designed for distributing them on multiple machines. That is exactly COM add-ins were introduced for. In that case you will be able to create an installer for your solution to get it deployed automatically for all users. Moreover, you will be able to check and install (if needed) the required prerequisites at the installation time. See Walkthrough: Create your first VSTO Add-in for Outlook to get started quickly.

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

發表留言