Consulting

Results 1 to 5 of 5

Thread: move images to specific position

  1. #1

    move images to specific position

    Hello,


    well, I'm trying to get a possible way for a macro can move all non inline images (flowing images) with a specific criteria as following for ex.






    A= get the page width size (215.9 mm) whatever it is
    1.jpg




    B= get the image width size (60.96 mm) whatever it is

    2.png




    C= get the Absolute position for image in page (32.3 mm) whatever it is

    3.jpg



    then make (A) - (B) - (C) = the new position for image in page


    215.9 - 60.96 - 32.3 = 122.64


    4.jpg




    Notes:


    - all changes should be to the page not margin


    - all changes should be applied for non inline images only (flowing images)



    samples file is attached for before and after.
    Sample.docx

    Thanks in advance


    Cross-posting link : here

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,337
    Location
    You can try this:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 1/2/2019
    Dim sngPW As Single, sngPH As Single
    Dim oShp As Shape
      sngPW = ActiveDocument.PageSetup.PageWidth
      For Each oShp In ActiveDocument.Shapes
        oShp.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        oShp.Left = sngPW - oShp.Width - oShp.Left
      Next
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    AMAZING!

    it works very well, but there are just two matters

    The first is that the final position should be 122.6 mm as shown on the last screenshot on main topic

    but in your macro i found it be 122.7 mm !!

    the second thing, can you add a counter at the end of macro to count how many images have been moved


    really your help is highly appreciated

    Thanks in advance

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,337
    Location
    You're welcome.

    I suppose it is a rounding issue but can't say for sure. Absolute position is not something that you can return directly with VBA.

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 1/2/2019
    Dim sngPW As Single, sngPH As Single
    Dim oShp As Shape
    Dim lngCount As Long
      sngPW = ActiveDocument.PageSetup.PageWidth
      For Each oShp In ActiveDocument.Shapes
        oShp.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        oShp.Left = sngPW - oShp.Width - oShp.Left
        lngCount = lngCount + 1
      Next
      MsgBox lngCount
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    many thanks again for your generous help Greg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •