none
VTSO | Microsoft Word | Shapes. RRS feed

  • Question

  • Hi,

    I'm trying to work out the top left position relative to the page of a shape object  on a page in MS Word. So far I have:

                      

                switch (shape.RelativeHorizontalPosition)
                {
                    case WdRelativeHorizontalPosition.wdRelativeHorizontalPositionColumn:

                        left = ?;
                        break;

                    case WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin:
                        left = shape.Left + Globals.ThisAddIn.Application.ActiveDocument.PageSetup.LeftMargin;
                        break;
                    case WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage:
                        left = shape.Left;
                        break;
                }

                switch (shape.RelativeVerticalPosition)
                {
                    case WdRelativeVerticalPosition.wdRelativeVerticalPositionParagraph:

                        top = ?;
                        break;

                    case WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin:
                        top = shape.Top + shape.TextFrame.TextRange.PageSetup.TopMargin;
                        break;
                    case WdRelativeVerticalPosition.wdRelativeVerticalPositionPage:
                        top = shape.Top;
                        break;
                }

    but I'm really confused about the two possibilities with the ?'s in.

    Any help / guidance would be much appreciated.

    Martin

    Friday, June 1, 2018 2:35 PM

All replies

  • Hi Martin,

    To get the position of a shape relative to page, we can always compute based on the anchor.

    For example, the left of shape relative to page should be like below:

    Debug.Print Shape.Anchor.Information(wdHorizontalPositionRelativeToPage) + Shape.Left

    So does for the vertical position of shape:

    Debug.Print Shape.Anchor.Information(wdVerticalPositionRelativeToPage) + Shape.Top

    Hope it is helpful.

    Regards & Fei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 4, 2018 7:12 AM
    Moderator
  • Hi Fei,

    Many thanks for getting back to me on this. I'll try it out now...

    Martin

    Wednesday, June 6, 2018 8:10 AM
  • Hi Martin,

    If you still have problem about this issue, please feel free to let me know.

    Regards & Fei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 7, 2018 1:37 AM
    Moderator