Share via

How to write code for macro to do “Absolute Horizontal Position”, “Top and Bottom Text Wrapping", "Absolute Height and Absolute Width”?

Anonymous
2023-03-01T07:33:42+00:00

I need “Absolute Horizontal Position 0.6”, “Top and Bottom Text Wrapping” and “Absolute Height 7.3 inch. Absolute Width 5.5 inch”

I tried this code found on internet.

Dim x As Long

With ActiveDocument

    For x = 1 To .InlineShapes.Count

        With .InlineShapes(x)

            .LockAspectRatio = msoFalse

            .Height = InchesToPoints(7.3)

            .Width = InchesToPoints(5.5)

        End With

    Next x

End With

It works for the size but I need Horizontal Position and Top and Bottom Text Wrapping. How to write codes for those in one macro? Or do I need separate macros to do those? I have 0 knowledge of programming.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

John Korchok 232.4K Reputation points Volunteer Moderator
2023-03-01T16:17:23+00:00

Another piece of crap code from AnnaThomas, who apparently doesn't test anything before posting.

You can't set the position or text wrapping of inline shapes. They act as characters in a text string, so you can't set their position on a page. Since they are treated as text, you can't make text wrap around them.

The error in your code is from having a Sub statement without an End Sub after it. Delete the first 5 lines of your listing.

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

8 additional answers

Sort by: Most helpful
  1. John Korchok 232.4K Reputation points Volunteer Moderator
    2023-03-01T18:55:46+00:00

    As I replied earlier "You can't set the position or text wrapping of inline shapes. They act as characters in a text string, so you can't set their position on a page. Since they are treated as text, you can't make text wrap around them."

    Your shapes are inline, not floating, so Jay's VBA won't work for you either.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2023-03-01T17:31:32+00:00

    As John says, the position and text wrapping of inline shapes can't be changed. However, if your images are all floating (i.e., not inline), then the macro that Anna posted can be made to work with just a couple of small changes to make it handle Shape objects instead of InlineShape objects:

    Sub SetShapeProperties()
     Dim x As Long
     With ActiveDocument
     For x = 1 To .Shapes.Count
        With .Shapes(x)
           .LockAspectRatio = msoFalse
           .Height = InchesToPoints(7.3)
           .Width = InchesToPoints(5.5)
           .Left = InchesToPoints(0.6)
           .WrapFormat.Type = wdWrapTopBottom
        End With
     Next x
     End With 
    End Sub
    

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-03-01T14:43:35+00:00

    it didn't work. it giving me this error.

    i have like 64 images. i want to do the same to all the images.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-03-01T10:24:13+00:00

    Hi Rezve

    I'm AnnaThomas and I'd be happy to help you with your question. In this Forum, we are Microsoft consumers just like yourself.

    To set the absolute horizontal position of an inline shape, you can use the . Left property. To set the top and bottom text wrapping, you can use the . WrapFormat.Type property.

    Sub SetInlineShapeProperties() Dim x As Long With ActiveDocument For x = 1 To . InlineShapes.Count With . InlineShapes(x) . LockAspectRatio = msoFalse . Height = InchesToPoints(7.3) . Width = InchesToPoints(5.5) . Left = InchesToPoints(0.6) ' set absolute horizontal position . WrapFormat.Type = wdWrapTopBottom ' set top and bottom text wrapping End With Next x End With End Sub

    I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

    Best Regards,

    AnnaThomas

    Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.

    Was this answer helpful?

    0 comments No comments