Lets Learn

Opinion Matters

Have you ever thought of inserting an HTML page into Word directly?

Posted by Ankush on July 11, 2017


Have you ever thought of inserting an HTML page into Word directly?

Well, it is very easy.

Simply call ActiveDocument.Range.InsertFile “test.htm”, , , True

Here is the source code for test.htm

==
<html>
This is the image
<img width=625 height=500 src=”image002.jpg”>
</html>
==

But here comes the interesting part. Let’s say you have some images referenced in the HTML page and you insert this HTML page into Word document. Now just delete (rename) the image referenced in the HTML page and open the Word document, you don’t see the images in the document anymore..WHY???

Because they are linked. So to unlink them

====
Sub test()
ActiveDocument.Range.InsertFile ” test.htm “, , , True
ActiveDocument.Fields.Unlink
ActiveDocument.Save
End Sub
====

This code works fine in Word 2003 but doesn’t work in Word 2007 for some reason. To make this to work, you need to call an extra save. Here is an updated code

===============
Sub test()
ActiveDocument.Range.InsertFile “C:\Users\Administrator\Desktop\a.htm”, , , True
ActiveDocument.Save
ActiveDocument.Fields.Unlink
ActiveDocument.Save
End Sub
==============

Hope this helps!!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: