Results 1 to 12 of 12
  1. #1
    Lounger
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search for soft return (VBA / wORD / 2000)

    I need to be able to find when information has wrapped in a Word Table Cell - I initially though that I could search for a soft return using LF and attempted using the following code:

    Sub Test()
    Dim rngCellTest As Range

    Set rngCellTest = ActiveDocument.Tables(1).Cell(2, 3).Range

    rngCellTest.Find.ClearFormatting
    With rngCellTest.Find
    .Text = vbLf
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    If rngCellTest.Find.Execute = True Then
    MsgBox "true"
    Else
    MsgBox "false"
    End If
    End Sub

    This doesn't work. Does anyone have any suggestions?

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    Cathy,

    The special characters for doing a find on a manual line break aka soft return are "^l" (caret-pipe - dunno what else you call it) so perhaps you could try substituting this for vbLf as the Find text.

    When you say "information has wrapped in a Word table cell", you're referring specifically to lines that have a soft return at the end? - 'cause text will wrap in a Word table cell with or without a soft return (and it would be pretty hard to track down the latter via code I'd say).

    Gary

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    Gary - have you actually used that combination? Only it's not caret-pipe, it's caret-small L ... I use it frequently when straightening out much-forwarded emails ... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Beryl M


  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    Beryl,

    Oops - what was I thinking? <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    Thanks for straightening me out - caret-small el it is!

    Gary

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    The codes are different in a table cell, you need to look for the sequence 13 and 7.

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    No, ^13^7 is the end-of-cell marker (there are two of those at the end of a row).
    The manual line break ^l has the ASCII code ^11. The VBA constant vbVerticalTab happens to have the same code, so you could use that, too, but it sure would confuse any Word user.
    To locate the end of lines that break because the text does not fit in a single line, you would need the Selection, and .Expand(wdLine) or .MoveDown(wdLine).

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Regards, Klaus

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    Right, I was testing for 13 7.
    vbVerticalTab is 11 and is one of the dumbest names for a constant.

  8. #8
    Lounger
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    Thanks for all the suggestions, but I am trying to determine when text wraps in a table cell. From your responses, 'soft return' was the incorrect term (but I now know how to find one!!).

    Any more suggestions?

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    This is a crude method: push the insertion point down a line and see if you are still in the same cell (by checking the row number or whether you might have exited the table entirely). This will tell you whether there is more than one line of text in a cell, but can't tell you whether this happened because the line wrapped automatically or the user entered a break of some kind. My testing was limited, YMMV.
    <pre>Function LineWrapped(myCell As Range) As Boolean
    myCell.Collapse wdCollapseStart
    myCell.Select
    'those two lines probably could be reversed: select the cell, then collapse the selection
    Selection.MoveDown wdLine, 1, wdMove
    If Selection.Information(wdWithInTable) = False Or _
    (Selection.Information(wdEndOfRangeRowNumber) <> _
    myCell.Information(wdEndOfRangeRowNumber)) Then
    'the line must not continue or you would still be in
    'the original range
    LineWrapped = False
    Else
    LineWrapped = True
    End If
    Application.GoBack
    Set myRange = Nothing
    Application.ScreenRefresh
    End Function</pre>

    Hope this helps.

  10. #10
    Lounger
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    I am a bit limited because I can't use the selection object (I will be running the application from VB controlling Word, which will be invisible). All code relates to application.document.range.

    The closest I have come to solving this problem is using the selection object to work out VerticalPositionRelativeToTextBoundary - this will return >0 if there is more than one line within the cell. Code is as follows:

    Sub Test4()
    Dim rngTest As Range
    Set rngTest = ActiveDocument.Tables(1).Cell(2, 3).Range
    rngTest.Select
    Selection.EndKey Unit:=wdLine
    MsgBox Selection.Information(wdVerticalPositionRelativeTo TextBoundary)
    End Sub

    EndKey only applies to the selection object, but if I can find an alternative using a range, this is what I would like to use.

    Any further suggestions?

    Cathy

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    A little bit simpler, if you are going to select the cell range, would be to then call the Word Count dialog - this will return a lines count for the selection.

    Forgive me for not posting code - am severely sleep-deprived! <img src=/S/doze.gif border=0 alt=doze width=15 height=15>

  12. #12
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Search for soft return (VBA / wORD / 2000)

    Cathy,

    Here's your code revised to illustrate using the WordCount dialog to return a line count for the cell:

    <pre>Public Sub GetRowCountInTableCell()
    Dim rngTest As Range
    Dim lngLines As Long

    Set rngTest = ActiveDocument.Tables(1).Cell(2, 3).Range
    rngTest.Select
    'must select the text; not the cell itself:
    Selection.MoveEnd Unit:=wdCharacter, Count:=-1

    With Dialogs(wdDialogToolsWordCount)
    lngLines = .Lines
    '.Display rather than .Execute seems to be needed
    'due to apparently sticky .Lines property
    .Display 1
    End With

    MsgBox "This cell contains " & lngLines & " line(s) of text."

    Selection.Collapse
    Set rngTest = Nothing
    End Sub
    </pre>

    Gary

Posting Permissions

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