Word Automation Error: ".FormattedText is not a by reference property"

B

Bill Coan

NOTE: This was posted earlier to vsnet.vstools.office under a different
subject line but received no response.

I'm having a problem automating Word's Find object from a .NET application,
using late binding.

If I use early binding, my code runs fine on most systems, but it is
vulnerable to a known bug explained here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;292744

The workaround to the bug is to use late binding instead of early binding,
but late binding has a problem of its own. The problem strikes me as a
generic automation problem and not a .NET interop problem.

I started with the following early-bound code:

Dim rngSource as Word.Range = wdDoc.Range.Paragraphs.Item(1).Range
Dim rngDestination as Word.Range = wdDoc.Range.Paragraphs.Item(2).Range
rngDestination.FormattedText = rngSource.FormattedText

After reading the above-referenced article, I switched to late-bound code as
follows:

Dim rngSource as Object = wdDoc.Range.Paragraphs.Item(1).Range
Dim rngDestination as Object = wdDoc.Range.Paragraphs.Item(2).Range
rngDestination.FormattedText = rngSource.FormattedText

NOTE: wdDoc is declared and instantiated elsewhere in my code and is NOT the
source of the problem.

When the late-bound code runs, I get the following error:

".FormattedText is not a by reference property"

Can anyone suggest how to access the .FormattedText property (and other "not
by reference" properties) of a late-bound object? Within .NET, is there some
way to use Reflection to access such properties?

Bill Coan
(e-mail address removed)
 
H

Helmut Obertanner

Hi,

have you tried:

x = rngSource.FormattedText
rngDestination.FormattedText = x

Maybe this helps.
Greets, Helmut Obertanner
 
B

Bill Coan

Hi Helmut,
x = rngSource.FormattedText
rngDestination.FormattedText = x

Thanks for taking a stab at this. I tried your idea, to no avail. With x
declared as Object, the first line runs but the second triggers the error
that has plagued me from the beginning.

Fellow VB-types have been so bereft of ideas that I may have to drop into a
CSharp group and see if someone there can at least explain how the process
is breaking down, even if there's nothing that can be done about it.

Bill Coan
(e-mail address removed)
 
C

Cindy M -WordMVP-

Hi Bill,
I'm having a problem automating Word's Find object from a .NET application,
using late binding.

If I use early binding, my code runs fine on most systems, but it is
vulnerable to a known bug explained here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;292744
Have you seen this KB article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;313104

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
B

Bill Coan

Have you seen this KB article:

Hi Cindy,

Thanks, but this is essentially the same article as the one I referenced in
my question. No new information there. Both articles /recommend/ late
binding, which is the cause of the problem I'm trying to solve.

A number of fellow MVPs have offered some useful suggestions for further
research. I will post back here after I've had an opportunity to complete my
research.

Bill Coan
(e-mail address removed)
 

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