Oleg Volodin

Hello All! Help me please: How I can get Word::Range interface with RangeFromPoint() method.

Thank you very much, Volodin Oleg.



Re: Visual Studio Tools for Office Get Range from Word

X4U

Hello Oleg,

The RangeFromPoint gives you null, a Shape or a Range object (as I know).

You can try it like this:

object result = this.Application.ActiveWindow.RangeFromPoint(100, 200);

if (result is null)

{

// Nothing

} else if (result is Word.Range) {

Word.Range range = (Word.Range) result;

// TODO:

} else if (result is

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office Get Range from Word

Cindy Meister

Hi Oleg

The question is actually off-topic for this forum and should be asked in one of the newsgroups listed in the Please Read First resource at the top of the forum. However, here's a hint (VBA code) to get you going in the right direction

Dim rng As Object
Dim pLeft As Long, pTop As Long, pHeight As Long, pWidth As Long
Dim wind As Word.Window

Set wind = ActiveDocument.ActiveWindow
wind.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range
Set rng = wind.RangeFromPoint(pLeft + 50, pTop + 50)
rng.Select
rng.Text = " new text "

Note that the range you want to return must be declared as an object. Also, you can't use named parameters for the RangeFromPoint method. If you need assistance converting VBA code to the programming language you're using, please address the request to a resource listed in the posting mentioned above, or to a group that specializes in the programming language you're using. This forum deals only with VB.NET and C#.






Re: Visual Studio Tools for Office Get Range from Word

Oleg Volodin

Thanks for all, bur I want do it in C++:

Word::RangePtr pRange;

Word::Range NeoRange;

pRange = NeoWord->Application->ActiveWindow->RangeFromPoint( Pt.x, Pt.y );

NeoRange = pRange.GetInterfacePtr();

Thanks to Pentx!





Re: Visual Studio Tools for Office Get Range from Word

Cindy Meister

Hi Oleg

<<Thanks for all, bur I want do it in C++:>>

As I mentioned in my first reply, this forum is for questions concerning the VSTO technology, and VSTO does not include C++. I realize it is difficult to find help using C++ to automate Word, but you'll need to use the newsgroup resources in the Please Read First message, as I indicated.

One more tip, from the code in your last reply: if you need to base a second range on an existing one, and use them independently, then:

NeoRange = pRange.Duplicate

If you use a construct like NeoRange = pRange you're actually using the same pointer, so change to one will affect the other. Duplicate will create a second pointer to the Range stored on the heap.