none
Move With Text property on frame object in Word RRS feed

  • Question

  • Hi

    I am trying to programatically change the "Move with text" value of a series of frames within a Word document.  I can get a handle to the frames collection and loop through them with no issue.  The only problem I have is that the "Move with text" property does not seem to be exposed by the Word API.  

    I've search the Office API documentation on MSDN and cannot see a reference to it anywhere.  

    Can anyone help me??

    Thanks in advance,
Mike. 

    Thursday, November 10, 2011 11:55 AM

Answers

  • Hi Mike

    You can't get the position of the frame, but you can of the text range within it:

    ActiveDocument.Frames(1).Range.Information(wdVerticalPositionRelativeToPage)

    So you can store this in a variable (of datatype Single) then calculate the difference. The following worked for me in a quick test.

    originalPos = ActiveDocument.Frames(1).Range.Information(wdVerticalPositionRelativeToPage)
    ActiveDocument.Frames(1).RelativeVerticalPosition = wdRelativeVerticalPositionPage
    ActiveDocument.Frames(1).VerticalPosition = originalPos


    Cindy Meister, VSTO/Word MVP
    Friday, November 11, 2011 8:31 AM
    Moderator

All replies

  • When you change the "Move with text" option in the user interface, it affects the relative horizontal and vertical positions of the frame, so these are the settings you have to alter in your code.

    Stefan Blom, Microsoft Word MVP
    Thursday, November 10, 2011 4:52 PM
  • Hi Mike

    Take a look at the RelativeHorizontalPosition and RelativeVerticalPosition properties. These take a value from Enumerations with similar names. You need one of the values that is not part of the text. For example, wdRelativeVerticalPositionPage instead of wdRelativeVerticalPositionParagraph.


    Cindy Meister, VSTO/Word MVP
    Friday, November 11, 2011 7:13 AM
    Moderator
  • Thanks for the advice.

    I've tried setting the RelativeVerticalPosition and that does have the effect of unchecking the "Move with text" checkbox.  The problem I have now is it shifts the frame up slightly.  I've noticed when you uncheck the option in Word it alters the vertical position value automatically - I am assuming Word calculates the distance from the top of the page for the frame's current location in order to do this.  I can't find how it gets this value - any ideas?

    Thanks for your help,

    Mike.

    Friday, November 11, 2011 8:10 AM
  • Hi Mike

    You can't get the position of the frame, but you can of the text range within it:

    ActiveDocument.Frames(1).Range.Information(wdVerticalPositionRelativeToPage)

    So you can store this in a variable (of datatype Single) then calculate the difference. The following worked for me in a quick test.

    originalPos = ActiveDocument.Frames(1).Range.Information(wdVerticalPositionRelativeToPage)
    ActiveDocument.Frames(1).RelativeVerticalPosition = wdRelativeVerticalPositionPage
    ActiveDocument.Frames(1).VerticalPosition = originalPos


    Cindy Meister, VSTO/Word MVP
    Friday, November 11, 2011 8:31 AM
    Moderator
  • Brilliant - I'll give that go!  Cheers for the quick response :)

    Friday, November 11, 2011 9:15 AM