Results 1 to 12 of 12
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Extract Address Code (Word 97 -RS2)

    The .extractaddress argument of the ToolsEnvelopesAndLabels() dialog is woefully deficient. For
    example, if the the address lines end with newline instead of
    paragraph marks, Word will not "pick up" the address. If you
    select the address and also grab two paragraph marks --
    say, from the next two lines after the address -- Word will pick
    up the address (and the unnesssary paragraph marks -- of
    course!); BUT, Word will only print the first line of the address.


    So, I want to "manually" pick up the address. Word does a
    nice job of finding the address if the lines end with paragraph
    marks. I want to emulate that so that the paras are not
    required. I'm now accepting ideas for "address indicator
    criteria" so I know what to pick up. The rest should be pretty
    easy -- copy to range, convert newlines to paras, paste to
    the .AddrText argument.

    I figure the code has to move to the top line of the address
    look for numbers and stop selecting after two consecutive new lines or paras.

    How would you do this? Am I thinking on the wrong plane?

    Here's the dialog code I'm futzing with:

    <pre>Sub ToolsEnvelopesAndLabels()
    Dim dlg As Dialog
    Dim strAddress As String

    Set dlg = Dialogs(wdDialogToolsEnvelopesAndLabels)
    With dlg
    .DefaultTab = wdDialogToolsEnvelopesAndLabelsTabEnvelopes
    .EnvOmitReturn = True
    .EnvPaperName = "Automatically Select"

    If Selection.Range = "" Then
    'Assume IP in address somewhere
    'and move to the top of it
    With Selection.Find
    .ClearFormatting
    .Text = "^t"
    .Replacement.Text = ""
    .Forward = False
    .Execute
    If .Found Then
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    End If
    End With
    strAddress = Selection.Range.Text
    .addrtext = strAddress
    .Update
    Else
    .ExtractAddress = True
    End If
    Select Case .Display
    Case 0
    'Cancel or Close
    Case Else 'Any other selection gets executed
    .Execute
    End Select
    End With

    Set dlg = Nothing
    End Sub

    </pre>

    Attached is a sample of what needs to be picked up.
    Attached Files Attached Files
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    Well, leave me alone long enough and I'll come up with something...

    See if you can poke holes in this logic:

    If there's a zip code, there's an address. A zip code looks like
    5 numbers followed by either a hyphen (for zip+4) or a
    paragraph mark or a new line mark. I can't figure out now to
    test for all that with one Find, so I'm cheating (assuming) a bit.
    This: .Text = "[0987654321]{5}>" finds 5 numbers that end
    the word. So, 95876- 95867[newline] and 95876[para] will
    get me to the END of the address. (Still gotta figure out how
    to get to the beginning.)

    I think I'm pretty safe in not finding non-addresses with 5
    digits in a row. Anyone using that many numbers for $ or
    measurement would put commas in there.


    <pre>With Selection.Find
    .ClearFormatting
    .Text = "[0-9]{5}>"
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Forward = True
    .Execute
    If .Found Then
    Selection.MoveEnd Unit:=wdLine
    Selection.Collapse wdCollapseEnd
    Else
    'There's no address in this document
    Exit Sub
    End If
    End With
    </pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Extract Address Code (Word 97 -RS2)

    What are you going to do if they have an address but NO zip code or only the first 5 digits of one?
    Charlotte

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    >>If only the first 5 digits

    I account for that. Five digits is ok.

    No zip, no envelope. US Mail will not deliver w/o zip.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Extract Address Code (Word 97 -RS2)

    <hr>US Mail will not deliver w/o zip.<hr>
    And not infrequently even when there IS a zip. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>
    Charlotte

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    Including overseas/Canada/Mexico?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    You people are cruel. Name one day last week when the postal service failed to deliver, to your home, in a timely manner, a nice catalog of indoor gardening supplies or a flyer for a super deal on a equity loan or on new tires? Huh? You see, you're just negative, negative, negative...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    I'm doing a Word project for a legal office, and I too found the native envelope processing in Word to be woefully lacking. I came up with the following macro, which seems to work pretty well. In addition to properly working, it lets you have multiple names and addresses and will create an envelope for each of them.

    Any number of addresses will work. Any address format, zip, no zip, foreign, whatever will work. Only requirements:

    1: Addresses (except the last) need to be separated by a blank line (so the macro can find 2 consecutive paragraph marks between addresses). Therefore, you can't have a blank line WITHIN the addresses themselves. The final address can have as many blank lines after it as needed for readability. The bookmark (see #2 below) should enclose at least one paragraph mark after the final address.

    2: You need to have a bookmark around the address(es). In my case, I named it "Text_Addressee", but you could call it anything you like, by altering the macro.

    <pre>Sub CreateEnvelope()

    'Create envelope(s) for letters and pleadings.

    'Note: This macro requires that all addresses have a blank
    ' line after them. The addresses must be contained in
    ' a bookmark called "Text_Addressee". If this bookmark
    ' does not exist, the macro will advise the user and
    ' exit without creating envelope(s).


    'Check for addressee bookmark in document.
    If Not ActiveDocument.BookMarks.Exists("Text_Addressee") Then
    GoTo No_Envelope
    End If

    Application.ScreenUpdating = False

    'Select text in bookmark.
    Selection.GoTo What:=wdGoToBookmark, Name:="Text_Addressee"

    'Back the selection a character at a time until
    'the last character is not a paragraph mark.
    Do While Right$(Selection.Text, 1) = Chr$(13)
    Selection.MoveEnd Unit:=wdCharacter, Count:=-1
    Loop

    'Extend the selection to regain a paragraph mark.
    Selection.MoveEnd Unit:=wdCharacter, Count:=1

    'Copy the selection.
    Selection.Copy

    'Move to end of document, insert new section.
    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdSectionBreakNextPage

    'Setup envelope formatting for new section.
    With Selection.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientLandscape
    .TopMargin = InchesToPoints(2.25)
    .BottomMargin = InchesToPoints(0.5)
    .LeftMargin = InchesToPoints(4.25)
    .RightMargin = InchesToPoints(0.5)
    .Gutter = InchesToPoints(0)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(9.5)
    .PageHeight = InchesToPoints(4.13)
    .FirstPageTray = wdPrinterEnvelopeFeed
    .OtherPagesTray = wdPrinterEnvelopeFeed
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    End With

    'Force to page view.
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type <> wdPageView Then
    ActiveWindow.ActivePane.View.Type = wdPageView
    End If

    'Open header, unlink to previous.
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    ActiveWindow.ActivePane.VerticalPercentScrolled = 100
    Selection.HeaderFooter.LinkToPrevious = False

    'Go to footer, unlink to previous.
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Selection.HeaderFooter.LinkToPrevious = False

    'Open header, remove any text.
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.WholeStory
    Selection.Delete

    'Open footer, remove any text.
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Selection.WholeStory
    Selection.Delete

    'Exit header/footer, Add address(es)
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Selection.Paste

    'Remove the final paragraph mark from the document.
    Selection.EndKey Unit:=wdStory
    Selection.Delete Unit:=wdCharacter, Count:=1

    'Find prior section break
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^b"
    .Replacement.Text = ""
    .Forward = False
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Collapse wdCollapseEnd

    'To separate multiple addresses between envelopes, find any
    'double paragraph marks, and replace with page break(s)
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "^p^p"
    .Replacement.Text = "^p^m"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Application.ScreenUpdating = True
    Exit Sub

    No_Envelope:

    Beep
    MsgBox "All addresses must be enclosed in a bookmark" & vbCrLf _
    & "called ""Text_Addressee""." _
    & vbCrLf & vbCrLf _
    & "Each address needs a blank line after it." _
    & vbCrLf & vbCrLf _
    & "Please insert the needed bookmark and re-run this macro.", _
    vbCritical, "Missing Bookmark"

    Application.ScreenUpdating = True

    End Sub
    </pre>

    You'll see some stuff about 2/3 down about unlinking headers and removing text. This is only valid if your document had headers and/or footers in it, you may have to remove those sections, or make them conditional.

    Feel free to e-mail with questions.

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    Ron,

    Thanks for posting this. Loved your ReplaceText function. I'm still trying to work some magic with the envelope dialog. I've got the "pickup" working (sans bookmark) but there is an incredible bug I can't seem to crack. Once the address is assigned to the .AddrText property, only the first line prints even though the entire address shows in the box!

    I'm not sure my app can revert to a bookmark scenario as yours does, but it may to...

    I think Gary F and I are the only two coders in this hemisphere coding these darned dialogs. (Hi Gary!)
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Extract Address Code (Word 97 -RS2)

    Does that suggest anything to you, Kevin? <img src=/S/nuts.gif border=0 alt=nuts width=15 height=15>
    Charlotte

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Address Code (Word 97 -RS2)

    Well, stupidity comes to mind at first, but then again, I do get the code to work eventually and it's quite nice actually. That Envelope code works great, it's just to specific to our documents. I'm working on that...

    It's the missing documentation on those darned arguments that forces me to test test test.

    Our users all hit my dialog replacement code for save, saveas, open, fileclose, filecloseall, docclose, toolenvelopes and several others -- and they all work very well. It's just getting there.

    So, to answer your question completely, I'd have to say that at least Gary and I have tremendous tenacity and determination (to overcome the blind stupidity).
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Extract Address Code (Word 97 -RS2)

    As they say in the South, bless your hearts. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

Posting Permissions

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