Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open Word, paste text into a new doc BUT as HTML...

Status
Not open for further replies.

mp9

Programmer
Sep 27, 2002
1,379
GB
I'm using Word.Open and Documents.Add to open Word from my VB6 app and create a new document. I'm then pasting the contents of the clipboard in. This all works. So far, so unspectacular.

However, the text I'm pasting in from the clipboard is HTML. Since I'm only doing all this so I can use Word's spellchecker, I don't want to be checking HTML tags....

So, what I need is a way to force the new document created by Documents.Add to be a web page so that only the non-tag part of the HTML is spell checked.

Any ideas how to do this? And without Word adding all the surplus tags it normally does when creating a new web page from scratch.

Thanks in advance.
 
It's just a string in the clipboard.

The whole process of automating the creating of a Word document and pasting the clipboard contents in, I can do and that's all working fine...

...except that the document created by Documents.Add is .DOC format, not a web page and so the HTML gets pasted as straight text. Then when I automate the spellcheck it returns things like HREF as being misspelt. Clearly I do not want this!
 
One (non VB) method would be to add valid tag names to your personal dictionary

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
>It's just a string in the clipboard.

Yup, I'd got that bit. More to the point I suspect that that is all it is - a string (what the clipboard calls a Text format). The clipboard supports multiple formats, and it is these formats that allow you to paste (or allow the application you are pasting to to choose) the format you want.

If you have only got a string then you can only paste a string to Word (notwithstanding the fact that the content of the string looks like HTML to you), even if you switch to web format (which you can do with code such as ActiveWindow.View.Type = wdWebView)

So the point of my question was to try and determine if you could get the data onto the clipboard in a genuine HTML data format. If so, then you can simply Selection.PasteSpecial DataType:=wdPasteHTML no matter what the view.

Or you can do the conversion to the clipboardyourself:
Code:
[blue]' Requires a reference to the Microsoft HTML Object Library
' Takes a string (optionally with HTML tags in it) and copies it to the clipboard
' in a supported HTML data format
Private Function CopyAsHTMLFormatToClip(strHTML As String) As Boolean
     With New HTMLDocument
        .body.innerHTML = strHTML
        ' At this point we could extract body.innerText to get HTML tag-free text if we wanted
        CopyAsHTMLFormatToClip = .body.createTextRange().execCommand("Copy")
    End With
End Function[/blue]
 
Strongm, I like the idea of doing a PasteSpecial, I'll give that a try and let you know how it goes. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top