Word vba word wrap

True if Microsoft Word wraps text to multiple lines and lengthens the cell so that the cell width remains the same. Read/write Boolean.

expression.WordWrap

expression    Required. An expression that returns a Cell
object.

ShowWordWrap property as it applies to the Paragraph, ParagraphFormat, Paragraphs, and TextFrame objects.

True if Microsoft Word wraps Latin text in the middle of a word in the specified paragraphs or text frames. This property returns wdUndefined if it’s set to True for only some of the specified paragraphs or text frames. Read/write Long. This usage may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.

expression.WordWrap

expression    Required. An expression that returns one of the above objects.

Example

ShowAs it applies to the Cell object.

This example sets Microsoft Word to wrap text to multiple lines in the third cell of the first table so that the cell’s width remains the same.

ActiveDocument.Tables(1).Range.Cells(3).WordWrap = True
				

ShowAs it applies to the Paragraph, ParagraphFormat, Paragraphs, and TextFrame objects.

This example sets Microsoft Word to wrap Latin text in the middle of a word in the first paragraph of the active document.

ActiveDocument.Paragraphs(1).WordWrap = True
				
title keywords f1_keywords ms.prod api_name ms.assetid ms.date ms.localizationpriority

Paragraphs.WordWrap property (Word)

vbawd10.chm156762230

vbawd10.chm156762230

word

Word.Paragraphs.WordWrap

bf77cc49-c440-3c8e-7384-721658207386

06/08/2017

medium

Paragraphs.WordWrap property (Word)

True if Microsoft Word wraps Latin text in the middle of a word in the specified paragraphs. Read/write Long.

Syntax

expression.WordWrap

expression Required. A variable that represents a ‘Paragraphs’ collection.

Remarks

This property returns wdUndefined if it’s set to True for only some of the specified paragraphs. This property may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.

Example

This example sets Microsoft Word to wrap Latin text in the middle of a word in the first paragraph of the active document.

ActiveDocument.Paragraphs(1).WordWrap = True

See also

Paragraphs Collection Object

[!includeSupport and feedback]

This may not be exactly what the OP had in mind but I figured I’d share my VBA Word Wrap function since I couldn’t find anything on the web to do what I wanted.

This function insert CR+LF‘s into the string in order to wrap it, so the word wrap is maintained if the text is copied to another application, text-based or otherwise.

Function wrapText(strIn As String, Optional maxLen As Long = 110) As String
    Dim p As Long: wrapText = strIn
    Do
        p = InStrRev(wrapText, " ", p + maxLen) - 1
        wrapText = Left(wrapText,p) & vbCrLf & Right(wrapText, Len(wrapText)-p-1)
        Debug.Print Mid(Replace(wrapText, vbCrLf, "||"), p - 20)
        'Stop
    Loop While p + maxLen < Len(wrapText)
End Function

It defaults to maximum width of 115 characters but can optionally be changed to anything. It only breaks on spaces (the last one that appears on/before position #115), and it only inserts CR + LF’s (with the constant vbCrLf), but they can be adapted as required.

As an example of application, I was building complex SQL queries in Excel and wanted to copy the SQL over to the server app neat & tidy, instead of one giant line.

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Thanks. We have received your request and will respond promptly.

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It’s Free!

*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Word Wrap in VBA Editor

Word Wrap in VBA Editor

(OP)

3 May 04 18:58

Is there a way to set up word wrap in Visual Basic for Applications editor so when you have a long code it all appears on the monitor.  I can’t seem to find an option for it.  I have been able to do it using Visual Studio.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join Tek-Tips® Today!

Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.

Here’s Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More…

Register now while it’s still free!

Already a member? Close this window and log in.

Join Us             Close

Old

04-14-2017, 08:17 AM

bronc
bronc is offline

wrapping text using Word VBA Windows 7 64bit wrapping text using Word VBA Office 2010 64bit

Novice

wrapping text using Word VBA

 

Join Date: Apr 2017

Posts: 5

bronc is on a distinguished road

Default

wrapping text using Word VBA


I spend a lot of time cutting an image from Paint into Word and then right clicking to choose Wrap Text and then Tight.

I would like to write some VBA to automate the wrapping (having first selected the «picture»).

I recall doing it in 2003 but cant work it out in 2010.
Not sure about the difference between InlineShape and Shape and Picture?
Any help appreciated.

Reply With Quote

Old

04-15-2017, 09:50 PM

Default


The default wrap option is in-line thus an in-line shape. To float the image you need to convert it to a shape and then set the wrap of the shape — so assuming that is the case there e.g.:

Code:

Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 16/04/2017 
Dim oShape As Shape
    Set oShape = Selection.InlineShapes.Item(1).ConvertToShape
    With oShape.WrapFormat
        .Type = wdWrapTight
        .Side = wdWrapBoth
        .DistanceTop = InchesToPoints(0.1)
        .DistanceBottom = InchesToPoints(0.1)
        .DistanceLeft = InchesToPoints(0.1)
        .DistanceRight = InchesToPoints(0.1)
    End With
lbl_Exit:
    Exit Sub
End Sub

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Old

04-16-2017, 12:09 PM

bronc
bronc is offline

wrapping text using Word VBA Windows 7 64bit wrapping text using Word VBA Office 2010 64bit

Novice

wrapping text using Word VBA

 

Join Date: Apr 2017

Posts: 5

bronc is on a distinguished road

Default


thats really helpful thanks a lot. just one thing:

there may be more than one inline object beside Item(1) present on the page.

I want to Select the one I want and then run the code to wrap it.

Reply With Quote

Old

04-16-2017, 08:46 PM

Default


Have you tried it? Item(1) is the first item in the selection. i.e. the selected image.

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Old

04-18-2017, 05:06 AM

bronc
bronc is offline

wrapping text using Word VBA Windows 7 64bit wrapping text using Word VBA Office 2010 64bit

Novice

wrapping text using Word VBA

 

Join Date: Apr 2017

Posts: 5

bronc is on a distinguished road

Default


It works a treat
v grateful for your expertise

Reply With Quote

Like this post? Please share to your friends:
  • Word vba selection words
  • Word vba selection expand
  • Word vba selection end
  • Word vba selection copy
  • Word vba selection all