formattedtext is not a reference error

G

gloeng

I'm automating Word2003 in VB.Net. I'm using late binding.
I want to put another document's content into the selected area of the
active document, without loosing its formatting.
I'm getting a 'formattedtext is not a reference property' error with the
following code

.... Selection.FormattedText = doc.Content.FormattedText ...

If this is a bug, does someone know another statement to achieve the same
result.
I'd like not to use clipboard.
 
J

Jezebel

It's not a bug. You just can't use the FormattedText property in that way,
because FormattedText is a Range object. There's no easy alternative to
copying the range.

in VBA (no idea what the VB.Net equivalent is) --

doc.content.copy
selection.paste
 
H

Helmut Weber

Hi Jezebel,

hmm.. I wonder, as this seems to work well here and now.

Selection.FormattedText = Documents(1).Content.FormattedText

documents(2) is activated, of course.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

Jonathan West

gloeng said:
I'm automating Word2003 in VB.Net. I'm using late binding.
I want to put another document's content into the selected area of the
active document, without loosing its formatting.
I'm getting a 'formattedtext is not a reference property' error with the
following code

... Selection.FormattedText = doc.Content.FormattedText ...

If this is a bug, does someone know another statement to achieve the same
result.
I'd like not to use clipboard.


It's not a bug, it's a syntax error. Try this

Selection.FormattedText = doc.Content

Or if you don't want to both with opening the document prior to inserting
its content, try using the InsertFile method instead
 

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