Share via

Setting text box format frame Width and Height to Auto

Anonymous
2023-08-01T11:54:20+00:00

Hi,

How do I program a macro to visit each text box format frame and set the values of Size,Width and Size.Height to Auto?

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

  1. Stefan Blom 340.3K Reputation points MVP Volunteer Moderator
    2023-08-01T12:52:54+00:00

    Text frames have their own collection called Frames. Try the following code:

    Dim f As Frame 
    
    Dim objDoc As Document 
    
    Set objDoc = ActiveDocument 
    
    For Each f In objDoc.Frames 
    
    f.HeightRule = wdFrameAuto 
    
    f.WidthRule = wdFrameAuto 
    
    Next f
    

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Stefan Blom 340.3K Reputation points MVP Volunteer Moderator
    2023-08-01T12:29:40+00:00

    A frame can be incorporated into a paragraph style, which is often the easiest way to work with them. Would that be a useful option for you? Or is it necessary to deal with frames in VBA?

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Suzanne S Barnhill 277.4K Reputation points MVP Volunteer Moderator
    2023-08-01T12:06:36+00:00

    Just to be clear, what you are formatting is a frame (which Word sometimes calls a "horizontal frame"), not a text box.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2023-08-01T12:41:45+00:00

    Hi,

    What I am doing is cut and pasting from other software. It puts the text into frames (horizontal frame) . However each frame cuts off some text because it is by default set to exact. What i need to do is reset all the frames by hand to auto sizing. Trying to write a macro to automate the task. Here is what I have but it does nothing

    Sub FormatTextsInTextBoxes()

    Dim objShape As Shape

    Dim objDoc As Document

    Set objDoc = ActiveDocument

    With objDoc

    For Each objShape In .Shapes 
    
      If objShape.Type = msoFrame Then 
    
        objShape.Height = AUTO 
    
        objShape.Width = AUTO 
    
      End If 
    
    Next 
    

    End With

    End Sub

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-08-01T12:17:51+00:00

    Hi,

    Thanks for that how do I refer to them in Word Macro language?

    Was this answer helpful?

    0 comments No comments