Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Word Macro (2000-2003)

    have a query regarding a Macro.



    I have a sequence of characters(sequence of strings) as "

    My name is Ankit and I am capable of doing many things. But I am afraid of bugs." like this.



    Now, I want that if I found a space between starting from 40 to 46th character in a single line, then My Macro will break the line from that point to the next line otherwise not. I want it to do it with every line.

    Like if I found space at 40th character then break the line from that point, otherwise if it found a space at 41st character then break the line from 41st character and son on.





    Like in the above example, I found my macro to do like this.

    "My name is Ankit and I am capable of doing

    many things. But I am afraid of bugs."







    Please help.





    Thanks

    Ankit

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Word Macro (2000-2003)

    Welcome to Woody's Lounge!

    The following macro will do what you ask:
    <code>
    Sub BreakLines()
    Dim lngStart As Long
    Dim bmk As Bookmark
    Dim rng As Range
    Dim strText As String
    Dim intPos As Integer
    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    Do
    lngStart = Selection.Start
    Set bmk = ActiveDocument.Bookmarks("Line")
    Set rng = bmk.Range
    strText = rng.Text
    intPos = InStr(40, strText, " ")
    If intPos >= 40 And intPos <= 46 Then
    rng.Start = lngStart + intPos
    rng.End = rng.Start
    rng.InsertBreak Type:=wdLineBreak
    End If
    Selection.MoveDown Unit:=wdLine
    Selection.HomeKey Unit:=wdLine
    Loop Until Selection.Start = lngStart
    Application.ScreenUpdating = True
    End Sub
    </code>
    But if you have a long line that doesn't happen to have a space in the 40th to 46th character because there is a long word in that position, that line will not be broken, which may not be what you intended.

  3. #3
    Star Lounger
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Word Macro (2000-2003)

    Thank you buddy........

    U r a true genious.......

    Thanks!!!!!!

Posting Permissions

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