Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Sylvain
 
Posts: n/a
Default Inserting HTML into word 2003 using VB.NET

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/247referenc...50/254902.aspx that I based
my code on, and his example works fine, but try adding over 20
characters instead of "test" h1testh1 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 1brtest 2"

Dim htmlText As String = "Version:0.9" & vbCrLf & "StartHTML:-1" &
vbCrLf & "EndHTML:-1" & vbCrLf & "StartFragment:000076" & vbCrLf &
"EndFragment:000128" & vbCrLf & "!DOCTYPE" & vbCrLf &
"HTMLBODYp" & tempStr & "/p/BODY/HTML"

Dim clipDO As New System.Windows.Forms.DataObject

clipDO.SetData(System.Windows.Forms.DataFormats.Ht ml, htmlText)

System.Windows.Forms.Clipboard.SetDataObject(clipD O, 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.

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Sylvain
 
Posts: n/a
Default Inserting HTML into word 2003 using VB.NET

What I ended up doing is simply create an html file (u have to add
htmlbody.../body/html or else it won't work even if your htm
file appears fine in IE), and inserted it into word using the
insertFile() method. That seems to work for me.

Thanks.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
take yet another lesson from wordperfect "reveal codes" wordperfect is superior Microsoft Word Help 5 May 11th 09 07:58 PM
how do i set up template in vbeditor without proggramming language ARRRGH New Users 4 October 1st 05 03:19 AM
Word 2003 Mailmerge problem - works in Word 2000 Rick Robinson Mailmerge 2 April 28th 05 10:16 AM
In Word, how can I see all files (*.*) in "save as"? citizen53 New Users 8 April 4th 05 04:56 PM
WP Delay Code - Word Equiv Mike G - Milw, WI Microsoft Word Help 6 January 10th 05 04:12 PM


All times are GMT +1. The time now is 10:04 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"