+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27

Thread: Paragraphing from Text

  1. #16
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Paragraphing from Text

    or
    Sub snb()
     sn = Split(Replace(activedocument.content, vbCr & vbCr, vbCr), vbCr)
     For j = 1 To UBound(sn)
      If Left(sn(j), 1) = LCase(Left(sn(j), 1)) Then sn(j) = "~" & sn(j)
     Next
    
     activedocument.content = Replace(Join(sn, vbCr), vbCr & "~", " ")
    End Sub



  2. #17
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Paragraphing from Text

    Sorry it's taken me so long to get back to this.

    ProtonLeah, I tried your code, and it did an excellent job. The only thing it didn't seem to catch was paragraphs that end in quotation marks.

    Abousetta, wow! I tried your code, and again the only problem was with quotation marks. See the paragraph below for a sample.
    You don't know how lucky you are to be loved." Meg said in a startled way, "I guess I never thought of that. I guess I just took it for granted." Calvin looked somber; then his enormous smile lit up his face again. "Things are going to happen, Meg! Good things! I feel it!" He began wandering, still slowly, around the pleasant, if shabby, living room. He stopped before a picture on the piano of a small group of men standing together on a beach. "Who's this?" "Oh, a bunch of scientists." "Where?" Meg went over to the picture. "Cape Canaveral. This one's Father.” "Which?" "Here." "The one with glasses?" "Yup. The one who needs a haircut." Meg giggled, forgetting her worries in her pleasure at showing Calvin the picture. "His hair's sort of the same color as mine, and he keeps forgetting to have it cut. Mother usually ends up doing it for him—she bought clippers and stuff—because he won't take the time to go to the barber." Calvin studied the picture. "I like him," he announced judiciously. "Looks kind of like Charles Wallace, doesn't he?" Meg laughed again. "When Charles was a baby he looked exactly like Father. It was really funny." Calvin continued to look at the picture. "He's not handsome or anything. But I like him." Meg was indignant. ""He is too handsome." Calvin shook his head. "Nah. He's ,tall and skinny like me.
    SNB and NickyC, I also tried your codes. They didn't seem to do anything noticeable, though Nicky's caused a lot of furious whirring before ending up with what looked to all intents and purposes like the original document I started with. I've attached the document I'm trying all of these macros on so you can tell me if I've done something wrong and can see the same results I'm seeing.
    Attached Files Attached Files

  3. #18
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Paragraphing from Text

     
    Sub snb()
     sn = Split(ActiveDocument.Content, vbCr)
     For j = 1 To UBound(sn)
      If Left(sn(j), 1) = LCase(Left(sn(j), 1)) And Val(Left(sn(j), 1)) = 0 Then sn(j) = "~" & sn(j)
     Next
     
     activedocument.Content = Replace(Replace(Join(sn, vbCr), vbCr & "~", " "), vbCr, vbCr & vbCr)
    End Sub
    PS. to see what has happened you should make all 'invisible' characters visible. (tabs, spaces, paragraph signs, etc.)
    Last edited by snb; 11-15-2011 at 10:43 AM.



  4. #19
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Paragraphing from Text

    Thanks SNB; good idea on making the invisible visible.

    Your latest rendition does a great job, but still having trouble with quotations. I don't think they'll ever be 100%, but I think we can get closer. See the text below:
    She smiled rather wryly. "Not most of the time." "A mother like that! A house like this! Gee, your mother's gorgeous! You should see my mother.
    
    She had all her upper teeth out and Pop got her a plate but she won't wear it, and most days she doesn't even comb her hair. Not that it makes much difference when she does." He clenched his fists. "But I love her. That's the funny part of it. I love them all, and they don't give a hoot about me. Maybe that's why I call when I'm not going to be home. Because I care. Nobody else does. 
    
    You don't know how lucky you are to be loved."
    Notice that we have some back-to-back quotation marks? If we have two quotation marks together, chances are good that we should have a paragraph break between them. Also, quotation marks usually travel in pairs; where there's one, there should be a second, with no paragraph break between. So, the paragraph break following "mother" shouldn't be there. I'm not understanding how your macro works, so don't know how to tweak it for these situations. I'd appreciate some help in understanding.

  5. #20
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Paragraphing from Text

    The macro is a one-to-one translation of what I suggested in English previously.
    To handle the Quotation marks:

    Sub snb()
     sn = Split(ActiveDocument.Content, vbCr)
     For j = 1 To UBound(sn)
      If Left(sn(j), 1) = LCase(Left(sn(j), 1)) And Val(Left(sn(j), 1)) = 0 Then sn(j) = "~" & sn(j)
     Next
     
     sn = Split(Replace(Join(sn, vbCr), vbCr & "~", " "), Chr(34))
     For j = 1 To UBound(sn) - 1 Step 2
      sn(j) = Replace(sn(j), vbCr, " ")
     Next
     ActiveDocument.Content = Replace(Join(sn, vbCr), vbCr, vbCr & vbCr)
    End Sub
    Last edited by snb; 11-15-2011 at 11:25 AM.



  6. #21
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Paragraphing from Text

    I think we have a problem with this last bit of code. When I run it it seems to delete a large portion of the quotation marks. See the same sample text I pasted earlier as it appears after running this macro:
    She smiled rather wryly. 
    
    Not most of the time.
    
     
    
    A mother like that! A house like this! Gee, your mother's gorgeous! You should see my mother.
    
    She had all her upper teeth out and Pop got her a plate but she won't wear it, and most days she doesn't even comb her hair. Not that it makes much difference when she does.
    
     He clenched his fists. 
    
    But I love her. That's the funny part of it. I love them all, and they don't give a hoot about me. Maybe that's why I call when I'm not going to be home. Because I care. Nobody else does.
    
    You don't know how lucky you are to be loved.

  7. #22
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Paragraphing from Text

    Not too complicated:

    Sub snb()
     sn = Split(ActiveDocument.Content, vbCr)
     For j = 1 To UBound(sn)
      If Left(sn(j), 1) = LCase(Left(sn(j), 1)) And Val(Left(sn(j), 1)) = 0 Then sn(j) = "~" & sn(j)
     Next
     
     sn = Split(Replace(Join(sn, vbCr), vbCr & "~", " "), Chr(34))
     For j = 1 To UBound(sn) - 1 Step 2
      sn(j) = Replace(sn(j), vbCr, " ")
     Next
     ActiveDocument.Content = Replace(Join(sn, chr(34)), vbCr, vbCr & vbCr)
    End Sub



  8. #23
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Paragraphing from Text

    No, but now we're back where we were. See the sample paragraph now:
    She smiled rather wryly. "Not most of the time." "A mother like that! A house like this! Gee, your mother's gorgeous! You should see my mother.
    
    She had all her upper teeth out and Pop got her a plate but she won't wear it, and most days she doesn't even comb her hair. Not that it makes much difference when she does." He clenched his fists. "But I love her. That's the funny part of it. I love them all, and they don't give a hoot about me. Maybe that's why I call when I'm not going to be home. Because I care. Nobody else does.
    
    You don't know how lucky you are to be loved."

  9. #24
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Paragraphing from Text

    What does it show ?
    Attached Files Attached Files
    Last edited by snb; 11-15-2011 at 12:31 PM.



  10. #25
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Paragraphing from Text

    Well, in this section we have back-to-back quotations, which should be separated by a paragrph break.
    She smiled rather wryly. "Not most of the time." "A mother like that! A house like this!
    In this section we have a paragraph break in the middle of a section bounded by quotation marks (if there is one quotation mark, the next paragraph break shouldn't come until after the next quotation mark, except in rare circumstances).
    "A mother like that! A house like this! Gee, your mother's gorgeous! You should see my mother.
    
    She had all her upper teeth out and Pop got her a plate but she won't wear it, and most days she doesn't even comb her hair. Not that it makes much difference when she does."
    Same thing with this section
    He clenched his fists. "But I love her. That's the funny part of it. I love them all, and they don't give a hoot about me. Maybe that's why I call when I'm not going to be home. Because I care. Nobody else does.
    
    You don't know how lucky you are to be loved."

  11. #26
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Paragraphing from Text

    Well, in this section we have back-to-back quotations, which should be separated by a paragraph break
    How come, what for ?

    meaning this ?

    She smiled rather wryly. "Not most of the time."
    "A mother like that! A house like this!

    Please reread your initial post.
    Last edited by snb; 11-15-2011 at 12:39 PM.



  12. #27
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Paragraphing from Text

    Right. If a person is speaking, their text is surrounded by quotation marks. If they speak five sentences, there's a quotation mark preceding the first sentence, and following the last sentence. So, if there are 2 quotation marks together, it indicates the end of one person speaking, and the beginning of another person speaking. Usual convention is that the speaker's dialogues are separated into distinct paragraphs. See below for how this particular section should be paragraphed:
    She smiled rather wryly. "Not most of the time." 
    
    "A mother like that! A house like this! Gee, your mother's gorgeous! You should see my mother.  She had all her upper teeth out and Pop got her a plate but she won't wear it, and most days she doesn't even comb her hair. Not that it makes much difference when she does." 
    
    He clenched his fists. 
    
    "But I love her. That's the funny part of it. I love them all, and they don't give a hoot about me. Maybe that's why I call when I'm not going to be home. Because I care. Nobody else does.  You don't know how lucky you are to be loved."

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0