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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert HTML at word Bookmark

Status
Not open for further replies.
I'd have thought yes definitely if you use XML.
 
try

Code:
Dim woobj As Word.Application
Set woobj = CreateObject("Word.Application")
With woobj
.Visible = True
.Documents.Open ("filename")
.Selection.GoTo What:=wdGoToBookmark, Name:="bookmarkname"
.ActiveDocument.Hyperlinks.Add Anchor:=.Selection.Range, Address:="[URL unfurl="true"]http://www.tek-tips.com/threadminder.cfm?pid=707",[/URL] TextToDisplay:="This tektip page"
End With
 
add this

Code:
 .Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    .Selection.Font.Italic = wdToggle
    .Selection.Font.Bold = wdToggle
 
Again can't, well not easily.
The whole picture is this is being generated on a server using a .net dll.

The client passes several html formatted strings to the dll, which are then put into the bookmarks.

I was trying originally to see if word had any special formating escape codes I could use to replace out the html.

I may have to pull the document in as html and then play with it, but not ideal.

}...the bane of my life!
 
If they were going to be all the same format you could easily do it using a Style. Simply insert the text at the bookmark with that Style (Character style).

However, I doubt if that is the case. What you are asking is if Word can GET format information from passed in text. Yes it can, at least from the clipboard. For example, assuming a bookmark named "here":
Code:
ActiveDocument.Bookmarks("here").Range _
   .PasteSpecial DataType:=wdPasteHTML
will dump the clipboard contents into the bookmark range, with the original HTML formatting.

faq219-2884

Gerry
My paintings and sculpture
 
wdPasteHTML "works from HTML code"? Are you trying to say it is not working? Are you saying that <b><i>Hello</i></b> works, but <strong>hello</strong> does not?

If so....it would help if you actually said so. Please try to be clear and concise.

faq219-2884

Gerry
My paintings and sculpture
 
Sorry I am saying it does not work at all.
If you try to paste <strong>hello</strong> or <b><i>Hello</i></b> that is exactly what you see in the word document.

I have done some more research and it appears there are some conversion steps needed including utf8 encoding.

}...the bane of my life!
 
But are you passing it in as a string or, as I mentioned, from the clipboard? The clipboard should not have HTML tags as text.

It may help if you actually posted some code.

faq219-2884

Gerry
My paintings and sculpture
 
The html code is passed to the application as a string yes.
So the clipboard has html tags in it.

I have seen that it is possible to do by encoding in a particular way before it enters the clipboard and attaching certain headers, but not seen a definitive way lol.

}...the bane of my life!
 
Huh??????
The html code is passed to the application as a string yes.
So the clipboard has html tags in it.
These are not connected.

If it is passed as a string, that MEANS it is passed as a variable (a string variable) OR it is passed as a string literal. In either case...there is no formatting.

So the clipboard has html tags in it. There is no "so".

A variable passed as a string is one thing (no format), the Clipboard contents (which can be many things including formatting; it could even be a graphic) are something else.

As you are not posting code I don't see I can offer much else as suggestions. I asked directly:

"But are you passing it in as a string or, as I mentioned, from the clipboard? "

You are answering (sort of): both.

Here is what you posted again:

The html code is passed to the application as a string yes.
So the clipboard has html tags in it.

If the first sentence is true, then you are passing <b><i>Hello</i></b> as literally that....text. It is NO meaning. As far as Word is concerned "<" is as meaningful as "o".

Passing a string is NOT the same as inserting the contents of the Clipboard.

faq219-2884

Gerry
My paintings and sculpture
 
It is a string.

There is no code to show, all i have is str="<b><i>Hello</i></b>"

I am merely trying to find out if there is any way of putting this into a word doc and have it appear in the document as bold itaic text.

I have sorted it using the htmlproject object and parsing the actual HTML of the document and inserting my html string that way.

Thanks for trying though.

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top