Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Deleting blank lines (WinXP OXP)

    I have developed a simple userform to print address details on envelopes when not using mailmerge.

    Some users do not like having blank lines in the addresses, eg where the position of the recipient is not known.

    I cannot seem to get the following code to work as required.

    If txtPosition = "" Then

    Selection.GoTo What:=wdGoToBookmark, Name:="bmkPosition"

    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1

    ActiveDocument.Bookmarks("bmkPosition").Delete

    Else
    Selection.GoTo What:=wdGoToBookmark, Name:="bmkPosition"
    Selection.TypeText Text:=txtPosition

    End If

    txtPosition = input field on userform

    I delete the bookmark separately as I found the delete was leaving it behind.

    Cheers
    cheers

    Phil Carter

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

    Re: Deleting blank lines (WinXP OXP)

    Why do you use bookmarks for each line? Wouldn't it be easier to use only a bookmark for the start of the address, and use Selection.TypeParagraph to insert a new line when needed - you can easily skip if if a text box on your form is empty.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Deleting blank lines (WinXP OXP)

    Hans thnaks for that

    I have taken on board what you have suggested and have changed my macro to suit. However, I can't get it to run and not insert a blank line when a position is not entered!

    Could you have a look at the attached for me as it is driving me nuts. I have tried changing the logic around (it has worked for me in the past) but this it still won't work.

    cheers
    cheers

    Phil Carter

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

    Re: Deleting blank lines (WinXP OXP)

    I think the main problem is that you are testing for txtPosition = False. This doesn't make sense, txtPosition contains a string that may or may not be empty, not a boolean. Try this code in the On Click event of the OK button:

    Private Sub cmdOK_Click()
    Selection.GoTo What:=wdGoToBookmark, Name:="bmkAddress"
    Selection.TypeText Text:=cboTitle.Value

    Selection.TypeText Text:=" "
    Selection.TypeText Text:=txtFirstName

    Selection.TypeText Text:=" "
    Selection.TypeText Text:=txtLastName

    If txtPosition <> "" Then
    Selection.TypeParagraph
    Selection.TypeText Text:=txtPosition
    End If

    Selection.TypeParagraph
    Selection.TypeText Text:=txtOrganisation

    Selection.TypeParagraph
    Selection.TypeText Text:=txtAddress

    Unload frmLabel
    End Sub

  5. #5
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Deleting blank lines (WinXP OXP)

    Hans

    Thanks very much for your help. Works a treat
    cheers

    Phil Carter

Posting Permissions

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