Consulting

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

Thread: Solved: Macro for carriage return

  1. #21
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Oh, and you keep mixing up the concept of a paragraph and a line break, which is probably why you seem dense

    In the way that Word thinks about these things (in as much as a program can think about something), there is considerable difference between a paragraph, and a blank line in the middle of a paragraph.

    While a type-writer will have no such problems, because it's just a page with some printed ink on it... a computer program views those two entities entirely differently.

    I suspect you should probably separate using paragraph marks rather than line breaks, but I'm basing that assumption on the fact that you've used the word paragraph at all.

    I think, strictly speaking, that a "carriage return" translates to a paragraph, while a "line feed" translates to a line break. Of course, I only say that because
    Selection.TypeText vbCr
    types a paragraph mark, but...
    Selection.TypeText vbLf
    types a line break

  2. #22
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    And it seems that Paul and I have much the same information and conclusions-- just a different format.

    Neener neener, Paul-- ^p was the answer

    Hope this helped, CodeBlue! Cheers!

  3. #23
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location

    I must be dense because I'm just not seeing the difference between shift/enter and enter as they both seem to bring them paragraph down one line.
    Like I said, i am not sure the OP is clear about blank line versus empty paragraph.

  4. #24
    you guys have been a major help!
    One prob I'm running into is after the page is divided into paragraphs some of the sentences are non-contigious as in part of a sentence is on one line then continued on the next. Is there a way to separate all the words by one char? I didn't see anything under the QLT.

  5. #25
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Pressing CTRL+SPACE will give you a "non-breaking" space. This is one of the many strategies in getting word to wrap where you want it to, without having to use a manual line break character.

    You can search for two spaces and replace all with a single space.

    Apart from those ideas, I'm confused what you're talking about. Can you be a little more descriptive?

  6. #26
    something like this...see attached. Not sure if that went thru or not.
    Attached Files Attached Files

  7. #27
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    That looks like scanned text. You could replace all paragraph marks with a space, and then all periods with a space and a paragraph mark... but there's no real easy solution to your problem. You need to try using a lot of different find/replaces... none of this is macro stuff, to my mind.

  8. #28
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    It would be interesting to see what the document looked like before the previous macros had been run. FWIW, you can clean up the attachment with a wildcard Find/Replace pair, where
    Find = ^l
    Replace = ^p
    Find = ([!^13^11])([^13^11])([!^13^11])
    Replace = \1 \3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #29
    I'm probably barking up the wrong tree here but I tried this code to find more than 1 space and replace it with one space
    [vba]
    Sub FindSpace()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = " "
    .Replacement.Text = " "
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    [/vba]
    but it didn't do anything.
    Actually I think I see part of the problem. It is looking for two spaces exactly and many times thru this doc it is much more than 2 spaces so it's not seeing anything to change.

  10. #30
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    I don't think it did anything because it looks like you're looking for exactly the same thing (two spaces) as you are replacing (two spaces).
    To me, it looks like you're trying to work up some macros to do document clean up on a scanned document. The problem with this approach is that scanned documents do not always have the same particulars... a macro you recorded for one document may be completely wrong for another document.

    My suggestion is that you skip the macro recording for awhile until you learn how to use find/replace really well. You may find that you really don't need macros at all... you just need to do a couple of quick find/replaces to get your document cleaned up as much as you need.

    When you start to see patterns in your document cleanup, you may find that you can get even faster by recording a couple of your more standard find/replace actions as macros, and then run those quickly with a single click.

    But this is all predicated on you understanding how to do basic find/replace a good bit better than you do right now.

    Does this make sense?

  11. #31
    Yes it makes sense I need an all-around better understanding of formatting et all. I know the code looks like it uses a two space in two places find and replace but actually in the macro it looks for two spaces to be replaced with one. Another formatting issue this time with vba.

    thanks for the input!

  12. #32
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Try:
    [VBA]Sub SingleSpace()
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[ ]{2,}"
    .Replacement.Text = " "
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    End With
    End Sub[/VBA]
    The above code uses a wildcard Find/Replace to replace all instances of two or more consecutive spaces with a single space in one pass.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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