Is it possible to change the position of an InlineShape?

P

Phil Crosby

I'm working with many InlineShapes and need to move them around the document.
Getting the Range they're anchored to and changing it (e.g. modifying "Start"
and "End" properties) doesn't seem to have any effect.

I can, in the Word document, cut and paste an InlineShape (thus moving it).
However, you have to select, in addition to the InlineShape, a character
before it or after it for the selection to "appear" and for you to be able to
cut it.

If I access the Range of the InlineShape programmatically and try and select
it or cut it, nothing happens. If I grow the range by a character, I _can_
select that, and then cut it. A hack way of moving the InlineShape is to
insert some whitespace before or after the InlineShape, select it, cut it,
and delete the whitespace on pasting.

Is there a less circuitous way of moving the InlineShape around in the
document?

(I realize, besides cutting and pasting, I can also use Range.Move() to move
it)

Someone in this thread mentioned the Shape.Range.Position property, which
VSTO doesn't expose apparently.
http://msdn.microsoft.com/newsgroup...ficedev-word&lang=en&cr=US&sloc=en-us&m=1&p=1

I posted this question previously in the VSTO forum, but they suggested I
come here.

Thanks
 
J

Jezebel

Use a Shape instead of an InlineShape. That's the whole point of the
difference: Shapes are floating and can be positioned anywhere on the page
that contains the anchor.
 
P

Phil Crosby

For my purposes, InlineShape is the right choice. I want the anchor to exist
at the character level, not the paragraph level.

Whether InlineShape or Shape is used, both should provide the ability to be
repositioned.
 
J

Jay Freedman

An InlineShape behaves like a single character. It doesn't have a
"position", it simply has a location in the sequence of characters. That's
why you can't reposition it.

You can do something like this, though:

Sub MoveInlineShape()
' Move the first InlineShape object
' from its current position to the end
' of the following paragraph.

Dim ils As InlineShape
Dim rgIls As Range
Dim rgDest As Range

Set ils = ActiveDocument.Range.InlineShapes(1)
Set rgIls = ils.Range

Set rgDest = rgIls.Paragraphs(1).Next.Range
With rgDest
.Collapse wdCollapseEnd
' rgDest is now at the start of the
' paragraph after the one we want, so
' move back one char
.Move unit:=wdCharacter, Count:=-1
.FormattedText = rgIls.FormattedText
End With

rgIls.Delete

Set rgIls = Nothing
Set rgDest = Nothing
Set ils = Nothing
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
P

Phil Crosby

What I mean by position is the location in the sequence of characters. Seems
we're equivocating on "position" vs. "location."

Collapsing the Range of the InlineShape I'm using has no effect. Maybe it's
because it's an ActiveX control... cutting and then pasting the shape in the
desired location has the same effect, and that seems to be working out great.

Thanks Jay.

-Phil Crosby
 
J

Jezebel

You can apply character positioning, like raised or lowered, if that's the
kind of positioning you have in mind.
 

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