Results 1 to 5 of 5

Thread: Delete line in word

  1. #1

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Exclamation Delete line in word

    Hi, I have written a small macro that pulls data from excel to populate a letter with data (eg name, address, and some selected paragraphs). here is an example of my code:

    VB Code:
    1. wordarray = Array(addressline1, addressline2, addressline3, addressline4, postcode, Policynumber, Yourref, ourref, date, salutation, para1, para2, para3, para4, signed, position)
    2.  
    3. wrd.Activedocument.Fields(1).Select
    4.     With wrd.Selection
    5.     .InsertAfter Text:=Addressee
    6.     End With
    7.  
    8.    For wrdroutine = 0 To 15
    9.     wrd.Selection.NextField.Select
    10.     With wrd.Selection
    11.     .InsertAfter Text:=wordarray(wrdroutine)
    12.     End With
    13.  
    14. Next
    15.    
    16.     End

    My problem is, sometimes para1 may not be applicable, and the same for the rest of the paragraphs. So I could have a letter that will have para2, para3 & para5. This will leave blank spaces were para1 & para4 are. Is there a way so that if para = "" (in this case para1 & para4) then it will delete that line where that are supposed to be input and the one below to bring the text up so there will not be 3 blank lines between the next paragraph entere don the letter?

    I hope this makes sense!

    many thanks
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Delete line in word

    I'm not quite sure how your code works (I assume you have a number of fields in a document, but I don't know what the fields are). Anyway...

    In your For Next loop can you do
    VB Code:
    1. Set f = wrd.Selection.NextField
    2. If wordarray(wrdroutine) = "" Then f.Delete
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Delete line in word

    thanks for that, will give that ago, not sure where to fit it in, but will try! thanks
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Delete line in word

    VB Code:
    1. wordarray = Array(addressline1, addressline2, addressline3, addressline4, postcode, Policynumber, Yourref, ourref, Date, salutation, para1, para2, para3, para4, signed, position)
    2.  
    3.   wrd.Activedocument.Fields(1).Select
    4.   With wrd.Selection
    5.     .InsertAfter Text:=Addressee
    6.   End With
    7.  
    8.   Dim f As Field
    9.  
    10.   For wrdroutine = 0 To 15
    11.     Set f = wrd.Selection.NextField
    12.     wrd.Selection.NextField.Select
    13.     With wrd.Selection
    14.       If wordarray(wrdroutine) = "" Then
    15.         f.Delete
    16.       Else
    17.         .InsertAfter Text:=wordarray(wrdroutine)
    18.       End If
    19.     End With
    20.   Next
    21.    
    22.   End
    This world is not my home. I'm just passing through.

  5. #5

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Delete line in word

    thanks alot, much appreciated
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

Posting Permissions

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



Click Here to Expand Forum to Full Width