View Full Version : Solved: More of Change style for paragraphs starting with "Chapter", etc.
Paul_Hossler
01-04-2009, 08:34 AM
Thanks to the help here, I've got my "automatic re-formatter" real close.
The automatic style applying works great (and more effeciently than I had originally) if the entire "title" is in one paragraph.
Sometimes however, the Chapter number is on one, and the Title text is on the next
In the attachment, Chapters 1 and 2 work great, Chapter 3 is a two line, and Chapter 4 does not have any Chapter title.
Could someone suggest the additional VBA to join the 2 lines if it's formatted like "Section 3a" AND the next para is "short", otherwise if it's formatted like "Section 4a" AND the next para is NOT "short"?
I'm still trying to figure out what "short" means. Best I could come up with "short" = 6 or fewer words.
I know that there will be false positives and some that get missed, but if I can get the majority of them handled, I'll be VERY happy.
Thanks
:hi: Paul
Paul_Hossler
01-05-2009, 05:32 PM
Perfect -- works great -- I never would have thought about using .Find like that.
Thanks
:beerchug:
Paul
Paul_Hossler
01-06-2009, 06:56 AM
Re-opening -- would you think I was picky if I asked if there was a faster way to test the first word?
Your logic works great, but on a 8000+ file it does seem to take a lot of time. I added a StatusBar display for the para number, and it's maybe .75 - 1 sec per paragraph as the loop steps down to 1.
Seems to act like it counts from .Paragraph(1) to .Paragraph(i) for each iteration of the loop to test .Words(1), and then goes back to .Paragraph(1) to count to .Paragraph(i-1), but that's just a guess.
Paul
fumei
01-06-2009, 03:12 PM
Just to demonstrate the above, it changes:
CHAPTER 1 - AAAAAAAAAAAAA AAAAAAAAA
Two words
CHAPTER 2 – WHATEVER IT IS REALLY HAPPENING
The second next best thing to being there makes ten words
CHAPTER 4 – YADDA YADDA
Five words are right here
into:
Chapter 1 - Aaaaaaaaaaaaa Aaaaaaaaa – Two Words
Chapter 2 – Whatever It Is Really Happening
The second next best thing to being there makes ten words
Chapter 4 – Yadda Yadda – Five Words Are Right Here –
Paul_Hossler
01-06-2009, 07:45 PM
I do not know what you mean by "does not have any Chapter title".
The TXT files seem to follow (generally) one of these formats
a. "Chapter #" + "title text" on one line, or
b. "Chapter #" with "title text" paragraph <= 6 words following, or
c. "Chapter #" with paragraph > 6 words following
a. H1 on the whole paragraph
b. Join 2 paragraphs, and make H1
c. Just make the first paragraph H1
In the attachment in my first post, Chapter 4 does not have ANY title. That's why I thought a test for 6 or less words on the para after the "Chapter" paragraph would suffice for the majority of cases to determine that there is a "Chapter #" but there is not a title
Macropod's code works great and has the advantage of being clear and therefore easily maintainable, but for the 8000+ paragraph txt file I used, it did take some time.
I'll mod my macro to include your code and see what happens.
Again, thanks to you both for all your help
Paul
BTW: My complete reformatting macro replaces ^p^p with ^p, multiple spaces with single space, and the other 'easy' stuff, but the "Chapter #" formatting was beyond me:think: So by the time I get to the "Chapter" part, empty paragraphs are deleted.
Update: Very nice improvement in speed, plus I learned some things from the pros. :beerchug:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.