S
Sylvain
Hi,
I'm trying to insert simple html code into a word document
programmatically, the only way I could think of doing this was by
adding the html code to the clipboard, and then pasting it in word
using an html format. selection.insertXML exists, but only inserts
wordML, and I couldn't find any insertHTML other than with the
pasteSpecial.
However if I have anything above 16 characters (depending on the html
tags), I get a (0x800A1066): command failed error. Here is a link
http://www.dotnet247.com/247reference/msgs/50/254902.aspx that I based
my code on, and his example works fine, but try adding over 20
characters instead of "test" <h1>test<h1> and this error will pop up.
Here is what I've done:
'Dim encoder As UTF8Encoding = New UTF8Encoding
'Dim tempStr As String = "123456789012345678901234567890" <- this won't
work
'--------------------------------------------------------
Dim tempStr As String = "test 1<br>test 2"
Dim htmlText As String = "Version:0.9" & vbCrLf & "StartHTML:-1" &
vbCrLf & "EndHTML:-1" & vbCrLf & "StartFragment:000076" & vbCrLf &
"EndFragment:000128" & vbCrLf & "<!DOCTYPE>" & vbCrLf &
"<HTML><BODY><p>" & tempStr & "</p></BODY></HTML>"
Dim clipDO As New System.Windows.Forms.DataObject
clipDO.SetData(System.Windows.Forms.DataFormats.Html, htmlText)
System.Windows.Forms.Clipboard.SetDataObject(clipDO, True)
oApplication.Selection.PasteSpecial(, , , ,
word.WdPasteDataType.wdPasteHTML)
'--------------------------------------------------------
If anyone knows how to successfully insert html code in word, please
let me know, I would greatly appreciate it.
Thank you,
sylvain.
I'm trying to insert simple html code into a word document
programmatically, the only way I could think of doing this was by
adding the html code to the clipboard, and then pasting it in word
using an html format. selection.insertXML exists, but only inserts
wordML, and I couldn't find any insertHTML other than with the
pasteSpecial.
However if I have anything above 16 characters (depending on the html
tags), I get a (0x800A1066): command failed error. Here is a link
http://www.dotnet247.com/247reference/msgs/50/254902.aspx that I based
my code on, and his example works fine, but try adding over 20
characters instead of "test" <h1>test<h1> and this error will pop up.
Here is what I've done:
'Dim encoder As UTF8Encoding = New UTF8Encoding
'Dim tempStr As String = "123456789012345678901234567890" <- this won't
work
'--------------------------------------------------------
Dim tempStr As String = "test 1<br>test 2"
Dim htmlText As String = "Version:0.9" & vbCrLf & "StartHTML:-1" &
vbCrLf & "EndHTML:-1" & vbCrLf & "StartFragment:000076" & vbCrLf &
"EndFragment:000128" & vbCrLf & "<!DOCTYPE>" & vbCrLf &
"<HTML><BODY><p>" & tempStr & "</p></BODY></HTML>"
Dim clipDO As New System.Windows.Forms.DataObject
clipDO.SetData(System.Windows.Forms.DataFormats.Html, htmlText)
System.Windows.Forms.Clipboard.SetDataObject(clipDO, True)
oApplication.Selection.PasteSpecial(, , , ,
word.WdPasteDataType.wdPasteHTML)
'--------------------------------------------------------
If anyone knows how to successfully insert html code in word, please
let me know, I would greatly appreciate it.
Thank you,
sylvain.