Home All Groups Group Topic Archive Search About

Pasting html into Word 2007

Author
16 Mar 2009 10:23 PM
Randy
Hi.  I need help.  I am having problems pasting an html string into
Word 2007.  The code (below) for Word Versions prior to 2007 (12)
works fine, but Word 2007 pastes the string as text with the
associated html tags displaying on the document.  Any ideas on this?

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim htmlValue as String


htmlValue = "<html><body>Test</body></html>"


'Open MS-Word via OLE.
Set oWord = CreateObject("word.application")
Set oDoc = oWord.Documents.Add()


'get version of word
If oWord.Version = 12 Then
    'Open a new document with the default template.
    Dim clipDO As DataObject
    clipDO.SetData htmlValue


    Clipboard.SetText htmlValue


    'Add text to the document.
    'Displays with html tags on page.
    oWord.Selection.Paste


Else
    'This works
    oWord.ActiveDocument.HTMLProject.HTMLProjectItems(1).Text =
htmlValue
    oWord.ActiveDocument.HTMLProject.RefreshDocument
End If


'Display MS-Word.
oWord.Visible = True
oWord.Activate

Author
19 Mar 2009 12:40 AM
Bill McCarthy
Hi Randy,

Does Word have a PasteSpecial in it's programming interface ?  If not you
might try removing the text from the clipboard and only leave the html
format.


Show quoteHide quote
"Randy" <randel.mc***@oscn.net> wrote in message
news:54e2d144-3d86-4258-912c-411a5e7b2349@z9g2000yqi.googlegroups.com...
> Hi.  I need help.  I am having problems pasting an html string into
> Word 2007.  The code (below) for Word Versions prior to 2007 (12)
> works fine, but Word 2007 pastes the string as text with the
> associated html tags displaying on the document.  Any ideas on this?
>
> Dim oWord As Word.Application
> Dim oDoc As Word.Document
> Dim htmlValue as String
>
>
> htmlValue = "<html><body>Test</body></html>"
>
>
> 'Open MS-Word via OLE.
> Set oWord = CreateObject("word.application")
> Set oDoc = oWord.Documents.Add()
>
>
> 'get version of word
> If oWord.Version = 12 Then
>    'Open a new document with the default template.
>    Dim clipDO As DataObject
>    clipDO.SetData htmlValue
>
>
>    Clipboard.SetText htmlValue
>
>
>    'Add text to the document.
>    'Displays with html tags on page.
>    oWord.Selection.Paste
>
>
> Else
>    'This works
>    oWord.ActiveDocument.HTMLProject.HTMLProjectItems(1).Text =
> htmlValue
>    oWord.ActiveDocument.HTMLProject.RefreshDocument
> End If
>
>
> 'Display MS-Word.
> oWord.Visible = True
> oWord.Activate
>
>