inserting webpage as text into word doc.

K

kraadde

I am looking for a script or some advises how to write a script that
sequentially opens several (specified) html pages, reads the text and
inserts it into a word document, one after the other.

A little help from my friends out there, please....
 
F

fumei via OfficeKB.com

The following will ROUGHLY do what you ask.

Option Explicit

Sub TryThis()
Dim file
Dim strPath As String
Dim ThisDoc As Document
Dim ThatDoc As Document
Set ThisDoc = ActiveDocument
strPath = "c:\myfiles\test\"
file = Dir(strPath & "*.html")
Do While file <> ""
Set ThatDoc = Documents.Open(FileName:=strPath & file)
ThisDoc.Range.Collapse 0
ThisDoc.Range.InsertAfter (ThatDoc.Range.Text) & _
vbCrLf
ThatDoc.Close
file = Dir
Loop
Set ThisDoc = Nothing
End Sub

It takes all HTML files in the folder c:\myfiles\test and grabs the text from
each, appending them, one after the other, into the active document.

I say rough, because, there is the big issue of any graphics. They are
brought in as ASCII character 1. Also, table cells are considered paragraphs
by Word. So an empty table cell will be considered a separate paragraph.

Is there a robust, clean, way to just get text, and ONLY text? Perhaps, but
I do not have time to work it out. Hopefully this may get you started.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top