Results 1 to 10 of 10

Thread: Strange character on table range text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    Paul/Paul,

    Yep elegant and probably the simplest in the list. I dug up my old ref file and thought I would post all five of the skinned cats that I am aware of:

    Sub ScratchMacro()
        Dim oCell As Cell
        For Each oCell In Selection.Tables(1).Range.Cells
            MsgBox fcnCellText1(oCell.Range.Text)
            MsgBox fcnCellText2(oCell.Range)
            MsgBox fcnCellText3(oCell.Range)
            MsgBox fcnCellText4(oCell.Range.Text)
            MsgBox fcnCellText5(oCell.Range)
        Next
    End Sub
    
    Function fcnCellText1(ByRef pStr As String)
        fcnCellText1 = Left(pStr, Len(pStr) - 2)
    End Function
    
    Function fcnCellText2(ByRef oRng As Range)
        oRng.MoveEnd wdCharacter, -1
        fcnCellText2 = oRng.Text
    End Function
    
    Function fcnCellText3(ByRef oRng As Range)
        oRng.End = oRng.End - 1
        fcnCellText3 = oRng.Text
    End Function
    
    Function fcnCellText4(ByRef pStr As String)
        fcnCellText4 = Replace(pStr, ChrW(13) & ChrW(7), "")
    End Function
    
    Function fcnCellText5(ByRef oRng As Range)
        'Slightly different as this also strips trailing empty paragraphs.
        oRng.MoveEndWhile Cset:=Chr(13) & Chr(7), Count:=wdBackward
        fcnCellText5 = oRng.Text
    End Function
    Last edited by Aussiebear; 12-28-2024 at 07:56 PM.
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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