Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 22 of 22

Thread: Convert Text to cells Sentences by Punctuation Marks

  1. #21
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by p45cal View Post
    I will still try and tweak the macro solution to read this 65001-encoded text file - but I'm out of time just now.
    It was easier than expected:
    Sub blah2()
    Dim at3() As String, objStream
    With CreateObject("ADODB.Stream")
      .Charset = "utf-8"
      .Open
      .LoadFromFile ("C:\Users\Public\Documents\dummy sentences.txt")
      ct = .ReadText()
      .Close
    End With
    
    Set Destn = ActiveSheet.Cells(1)
    dt = Split(ct, vbCrLf)
    j = 0
    For Each bt In dt
      at = Replace(Replace(Replace(Replace(bt, "...", "…¬"), ".", ".¬"), "?", "?¬"), "!", "!¬")
      at2 = Split(at, "¬")
      For i = 0 To UBound(at2)
        at2(i) = Application.Trim(at2(i))
        at2(i) = Replace(at2(i), "…", "...")    'optional to replace an ellipsis with 3 dots.
        If Len(at2(i)) = 0 Then at2(i) = "¬"
        ReDim Preserve at3(0 To j)
        at3(j) = at2(i)
        j = j + 1
      Next i
    Next bt
    at3 = Filter(at3, "¬", False)
    Destn.Resize(UBound(at3) + 1).Value = Application.Transpose(at3)
    End Sub
    Still interested in where these text files come from…
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  2. #22
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by p45cal View Post
    Still interested in where these text files come from…
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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