Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans helped me with a macro that accomplishes what I need; which is a document left with several paragraphs. These paragraphs are usually short and cause no problem when I paste them into my employer's database. However, since said database only allows for chunks of text up to 2,000 characters, including spaces, I have problems if the paragraph in question exceeds that size. Maybe Hans or you guys can help me extend Hans' macro so that it identifies those paragraphs larger than 2,000 characters, including spaces, and creates two chunks of text, one after the other, one up to 2,000 and the other with whatever is left. Any guidance is appreciated. Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    There's a problem: in the sample document that you attached to Post 760139, each line is a separate paragraph, and there are hard page breaks between lines that belong together. So how do we define a "paragraph"?

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are correct, Hans. What happened was that I combined your last macro with others you had helped me with before, and turned the document into something like the attached. The end product is several paragraphs separated by empty lines. Hope this helps!!!
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try this macro:
    Code:
    Sub SplitParas()
      Const SafeLength = 1990 ' Be on the safe side
      Dim par As Paragraph
      Dim lngLength As Long
      Dim i As Long
      Dim n As Long
      Dim rng As Range
    
      ' Loop through the paragraphs
      Set par = ActiveDocument.Paragraphs(1)
      Do
    	' Length of the text
    	lngLength = Len(par.Range.Text)
    	If lngLength > SafeLength Then
    	  ' If too long, set a range of the desired length
    	  Set rng = ActiveDocument.Range(par.Range.Start, _
    		par.Range.Start + SafeLength)
    	  ' But make sure it ends at a sentence end.
    	  rng.MoveEnd Unit:=wdSentence, Count:=-1
    	  ' Insert two paragraph marks (one would be OK too)
    	  rng.InsertParagraphAfter
    	  rng.InsertParagraphAfter
    	Else
    	  ' Otherwise, go on to the next
    	  Set par = par.Next
    	End If
      Loop Until par Is Nothing ' No more paragraphs
    End Sub

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Beautiful, Hans! Now I just have to study your handiwork. Thanks a bunch!

Posting Permissions

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