Hyperlinks lost when merging Word docs

D

dpirkle

I have the following C# code using COM interops to append one word doc to
another:

formatterDoc.Content.Copy();
object startPos = wordDoc.Content.End - 1;
object endPos = wordDoc.Content.End;
wordDoc.Range(ref startPos, ref endPos).Paste();

This works fine, generally, but if the document to append contains
hyperlinks, they appear in the merged document without hyperlink capability
or formatting (underlined blue text). All that is left of each hyperlink is
the text: you can't ctrl/click on the text to navigate to a linked site.

I found that if I replace the call to Paste() with a call to
PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting), the hyperlink
formatting will be retained, so that the text appears blue and underlined,
but the underlying hyperlink is still missing and non-functional.

Any suggestions on how I can retain the hyperlinks? This is for Word 2003,
by the way.
 
D

Doug Robbins - Word MVP

I know nought about C#, but try deleting the first line of code and replace
the last line with something like.

wordDoc.Range(ref startPos, ref endPos).FormattedText =
formatterDoc.Range.FormattedText;

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

dpirkle

Thanks so much for the suggestion. I just tried it out, and, sad to say, I
get the same results as before: the hyperlinks are neither hyper nor linking.
The funny thing is that if I record a macro to copy from one window and
paste into anoter, the macro works OK when I run it, and the hyperlinks are
fine. But trying to duplicate the same steps via interop calls to Word does
not work. Anyway, thanks again for the suggestion.
 
P

Peter Jamieson

Could be worth trying a PasteSpecial as you can specify RTF in that case,
but no idea if it works.

Example from VBA:

Selection.PasteSpecial Link:=False, Datatype:=wdPasteRTF, Placement:= _
wdInLine, DisplayAsIcon:=False
 
P

Peter Jamieson

Could be worth trying a PasteSpecial as you can specify RTF in that case,
but no idea if it works.

Example from VBA:

Selection.PasteSpecial Link:=False, Datatype:=wdPasteRTF, Placement:= _
wdInLine, DisplayAsIcon:=False
 
C

Cindy M.

Hi =?Utf-8?B?ZHBpcmtsZQ==?=,
Thanks so much for the suggestion. I just tried it out, and, sad to say, I
get the same results as before: the hyperlinks are neither hyper nor linking.
The funny thing is that if I record a macro to copy from one window and
paste into anoter, the macro works OK when I run it, and the hyperlinks are
fine. But trying to duplicate the same steps via interop calls to Word does
not work.
Word 2003 changed the way Paste works, and the defaults in the UI don't
necessarily correspond anymore to the defaults used by the object model. You
might check the PasteAndFormat method. And also take a look at the properties
associated with this enum: wdpasteoptions

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
D

dpirkle

PasteAndFormat gives better results, in that the formatting is retained and
hyperlinks still look like hyperlinks. But the actual link is lost, so
clicking on the hyperlink does not actually navigate to the site. I checked
out wdpasteoptions, but as far as I can tell, this is new to Office 2007, and
I need something that works with Office 2003. Thanks for the suggestion
though.
 
C

Cindy M.

Hi =?Utf-8?B?ZHBpcmtsZQ==?=,
PasteAndFormat gives better results, in that the formatting is retained and
hyperlinks still look like hyperlinks. But the actual link is lost, so
clicking on the hyperlink does not actually navigate to the site. I checked
out wdpasteoptions, but as far as I can tell, this is new to Office 2007, and
I need something that works with Office 2003.
One other possibility is that you have some kind of "security" software running
in the background that's checking the clipboard for possible "malicious
content". A hyperlink can be considered a security risk. When things don't work
"as expected", and others can't reproduce the problem, it's often something
else installed on your machine...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top