R
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
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