dc4life78
01-13-2009, 08:05 AM
Greetings all,
I have written a program to copy HTML data from an Internet Explorer object (file specified by the user) and paste it into a created Word document so that it can be formatted for conversion to PDF. The problem is that the format changes slightly regardless of what method I use to paste the data. Here is the intro code:
Dim oHtm As Object
Dim oWord As Word.Application
Dim oDoc As Word.Document
Set oHtm = CreateObject("InternetExplorer.Application")
oHtm.navigate (fullFileName)
oHtm.Document.execCommand "SelectAll"
oHtm.Document.execCommand "Copy
Set oWord = New Word.Application
oWord.Documents.Add
Set oDoc = oWord.Documents(1)
Here are some of the methods I have tried to use to paste the copied HTML data:
oDoc.Content.Paste
oWord.Selection.Paste
oDoc.Content.PasteSpecial DataType:=wdPasteHTML
All of these methods paste the data correctly but the H1, H2, and H3 headers are incorrectly formatted - it places a page-length horizontal line after each header and removes the dark blue font I have specified for headers in the CSS (text is now black.)
I tried using PasteAndFormat below and it does format the headers correctly, but for many HTML files it also inserts outline numbering throughout the entire text:
oWord.Selection.PasteAndFormat (wdFormatOriginalFormatting)
There is nothing in the original HTML code that would explain this phenomenon. Interestingly enough, however, when I pause the code operation after the intro code listed above and manually paste the data into the document (Control-V) it pastes perfectly, but I cannot seem to automate this specifc paste method. I have been unsuccessful in my attempts at using DoCmd (which I use all the time with Access but it does not seem to be compatible with the Word application or its objects) and SendKeys "^V" True (I read somewhere that SendKeys does not work with Vista, which I am running, but I have gotten the command to work in other programs.) Out of desperation I even tried tinkering with the Word paste options such as SmartCutPaste, yet all to no avail.
Any help would be appreciated; thanks in advance!
I have written a program to copy HTML data from an Internet Explorer object (file specified by the user) and paste it into a created Word document so that it can be formatted for conversion to PDF. The problem is that the format changes slightly regardless of what method I use to paste the data. Here is the intro code:
Dim oHtm As Object
Dim oWord As Word.Application
Dim oDoc As Word.Document
Set oHtm = CreateObject("InternetExplorer.Application")
oHtm.navigate (fullFileName)
oHtm.Document.execCommand "SelectAll"
oHtm.Document.execCommand "Copy
Set oWord = New Word.Application
oWord.Documents.Add
Set oDoc = oWord.Documents(1)
Here are some of the methods I have tried to use to paste the copied HTML data:
oDoc.Content.Paste
oWord.Selection.Paste
oDoc.Content.PasteSpecial DataType:=wdPasteHTML
All of these methods paste the data correctly but the H1, H2, and H3 headers are incorrectly formatted - it places a page-length horizontal line after each header and removes the dark blue font I have specified for headers in the CSS (text is now black.)
I tried using PasteAndFormat below and it does format the headers correctly, but for many HTML files it also inserts outline numbering throughout the entire text:
oWord.Selection.PasteAndFormat (wdFormatOriginalFormatting)
There is nothing in the original HTML code that would explain this phenomenon. Interestingly enough, however, when I pause the code operation after the intro code listed above and manually paste the data into the document (Control-V) it pastes perfectly, but I cannot seem to automate this specifc paste method. I have been unsuccessful in my attempts at using DoCmd (which I use all the time with Access but it does not seem to be compatible with the Word application or its objects) and SendKeys "^V" True (I read somewhere that SendKeys does not work with Vista, which I am running, but I have gotten the command to work in other programs.) Out of desperation I even tried tinkering with the Word paste options such as SmartCutPaste, yet all to no avail.
Any help would be appreciated; thanks in advance!