Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

programmatically move the anchor on a shape in a word document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Omatase - 26 Aug 2007 00:02 GMT
I have this code:

object offset = 1;
object unit = Word.WdUnits.wdLine;

mergeFields.ShapeRange.Anchor.LockAnchor = 0;
mergeFields.ShapeRange.Anchor.Move(ref unit, ref offset);

The anchor lock goes away so I know I have a reference to the correct
anchor object but I can't seem to move it anywhere.

Now granted the above code is not VBA but if someone can show me how
to do what I want in VBA I can translate it to C#. I just couldn't
find a forum that was for word AND C#.

Please help

Thanks
Russ - 26 Aug 2007 01:20 GMT
There doesn't appear to be a move method for an anchor. You can drag and
drop it, but I can't record a drag and drop.
Below are some pieces of information that might help.

This example repositions the selected shape object.
With Selection.ShapeRange
   .Left = InchesToPoints(0.6)
   .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
   .Top = InchesToPoints(1)
   .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
End With

This example creates a new document, adds a shape to it, and then locks the
shape's anchor.
Set myDoc = Documents.Add
Set myShape = myDoc.Shapes.AddShape(msoShapeBalloon, 0, 0, 140, 70)
myShape.LockAnchor = True
ActiveWindow.View.ShowObjectAnchors = True

Anchor Property Example
This example selects the paragraph that the first shape in the active
document is anchored to.
ActiveDocument.Shapes(1).Anchor.Paragraphs(1).Range.Select

   Selection.ShapeRange.Fill.Visible = msoTrue
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoTrue
   Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
   Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
   Selection.ShapeRange.LockAspectRatio = msoFalse
   Selection.ShapeRange.Height = 108#
   Selection.ShapeRange.Width = 144#
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionColumn
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionParagraph
   Selection.ShapeRange.Left = InchesToPoints(2.43)
   Selection.ShapeRange.Top = InchesToPoints(-0.25)
   Selection.ShapeRange.LockAnchor = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder ZOrderCmd:=4

> I have this code:
>
[quoted text clipped - 14 lines]
>
> Thanks

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Omatase - 30 Aug 2007 05:38 GMT
Thanks for the help but I have to be able to move the anchors. I found
a way to get word to auto move the anchor in some cases and that is by
calling IncrementTop(1f); on the shape. It doesn't always work
programmatically though even though it works consistently in the UI.

Any help is much appreciated.
Russ - 30 Aug 2007 06:07 GMT
This is from Word VBA Help:
****Quote
A shape is always attached to an anchoring range. You can position the shape
anywhere on the page that contains the anchor.
****UnQuote

The anchor is only dependable apparently for determining which page a shape
will stick to.

If you want a more dependable fix to certain text, then use an inline shape,
which acts like Character.

> Thanks for the help but I have to be able to move the anchors. I found
> a way to get word to auto move the anchor in some cases and that is by
> calling IncrementTop(1f); on the shape. It doesn't always work
> programmatically though even though it works consistently in the UI.
>
> Any help is much appreciated.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Omatase - 02 Sep 2007 05:01 GMT
The specific problem I'm having is that I am trying to copy some text
into a table. When I do, if there is a shape that has an anchor
attached to the text, then the shape moves inside the table with the
anchor. In Word 2003 or better I can turn the Layout in table cell
property off on the shape, but in word 2000 (which is what I have to
support) there is no such option. Moving the anchor fixes the problem,
but I can't get it to move.

Thanks for your continued help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.