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

    A Better Envelope Dialog (97 SR2)

    Enclosed is a more refined Envelope Printing dialog for use
    with documents that include address blocks. There are
    several assumptions made and several improvements over
    the built-in MS version. 1) the address must have a USA zip
    code consisting of 5 numbers or 5 numbers and a hyphen (to
    account for zip+4). I know nothing about postal codes for
    other countries. Feel free to enlighten me.
    2) the address block starts with either 2
    paragraph marks, a section or newpage break plus a
    paragraph mark or tab plus colon (to account for address
    blocks in memo format TO : -tab- ).

    One improvement is this code will extract the address if it is
    indented from the left margin. We have memorandum docs that look like this

    TO : Mr. James Smith
    1234 West 18th Street
    Los Angeles, CA 98765

    Word's extract address property (method?) will not extract
    this address.

    Put the IP before the first address in document, click your
    Envelope button (or Tools>Envelopes). The code finds the
    first address and picks it up. You print or cancel. Click the
    button again and the code finds the next address, etc.

    Give it a try and let me know if you find it useful or not.

    <pre>Sub ToolsEnvelopesAndLabels()
    Dim dlg As Dialog
    Dim strAddress As String
    Dim lngPrev1 As String
    Dim lngPrev2 As String
    Dim strAddr() As String
    Dim i As Long

    Set dlg = Dialogs(wdDialogToolsEnvelopesAndLabels)
    With dlg
    .DefaultTab = wdDialogToolsEnvelopesAndLabelsTabEnvelopes

    .EnvOmitReturn = True
    .EnvPaperName = "Automatically Select"

    'Move to first zip code
    Selection.Collapse wdCollapseStart
    With Selection.Find
    .ClearFormatting
    .MatchWildcards = True
    .Forward = True
    .Wrap = wdFindStop
    .Execute Findtext:="[0-9]{5}[^11^13^45]" 'it's a zip if it
    ends with newline, para or hyphen
    If .Found Then
    i = 1
    Selection.HomeKey
    Do While True
    ReDim Preserve strAddr(i)
    'Are we in a field?
    If ActiveDocument.Bookmarks
    ("Line").Range.Fields.Count > 0 Then
    strAddr(i) = ActiveDocument.Bookmarks
    ("Line").Range.Fields(1).Result
    Else
    'If not at top of document...
    Selection.EndKey unit:=wdLine,
    Extend:=wdExtend
    Selection.MoveEnd unit:=wdCharacter,
    Count:=-1 'Strip the line separator
    strAddr(i) = Selection.Text
    Selection.Collapse wdCollapseStart
    lngPrev1 = Asc(Selection.Previous
    (unit:=wdCharacter, Count:=1))
    lngPrev2 = Asc(Selection.Previous
    (unit:=wdCharacter, Count:=2))

    Select Case lngPrev1 & lngPrev2
    Case "13" & "12", "13" & "13", "9" & "58"
    'These two character combinations
    determine the top of the
    'address block, so quite looping when we
    get here.
    Exit Do
    End Select

    End If
    Selection.MoveUp unit:=wdLine, Count:=1
    i = i + 1
    Loop
    Else
    'No address found
    MsgBox "No address found. Click on an address to
    print an envelope. Try again.", _
    vbInformation, "Error: Print Envelope"
    Exit Sub
    End If
    End With

    For i = UBound(strAddr) To 1 Step -1
    strAddress = strAddress & strAddr(i) & Chr(13)
    Next
    .AddrText = strAddress
    .Show
    End With
    'Move IP to end of this address
    With Selection.Find
    .ClearFormatting
    .MatchWildcards = True
    .Forward = True
    .Wrap = wdFindStop
    .Execute Findtext:="[0-9]{5}[^11^13^45]"
    End With
    Selection.MoveDown unit:=wdLine, Count:=1
    Selection.Collapse wdCollapseStart
    Set dlg = Nothing
    End Sub
    </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>

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

    Updated Envelope Dialog (97 SR2)

    Updated to reflect some good ideas submitted and improved
    the extract functionality. Give it a try and make a reply cheers]

    Please see attached for code.
    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>

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    OK. I might steal some of your ideas .......

    I have two macros EnvelopeFromSelection and EnvelopeFromFile.

    The first collects all text from the start of paragraph contining the IP to the end of paragreaph (I have another macro that replaces hard para with soft para) and makes use of that.

    The second collects text from a file Env.txt which is created by a snapshot from my data base package and the file is erased first thing each morning.

    In both cases the text is set in an envelope form with return address etc.

    More in the next post.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    I thought that there was a discussion on snatching addresses, but I can't find it.

    I'm thinking of writing a clever snatch-and-analyse routine that will enable me to grab names and addresses from a web page, word document or text file, and coerce them into a standard format. Comma-delimited would do me fine.

    I thought of scanning text for a valid postal code and working forewards and backwards from there.

    That's when I thought I'd seen that discussion. If you know where it is, would you please post a link.

    Otherwise I'll have to start writing VBA again ......

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

    Re: A Better Envelope Dialog (97 SR2)

    The snatching, or extracting (the MS term for it) is in attachment. As far a a discussion goes, I don't recall. The reason I titled the Post "A Better..." was the extracting code I wrote works a lot better the the MS "method". I've improved on the posted code, so you're getting cold potatoes unless you ask for more.
    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>

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

    Re: A Better Envelope Dialog (97 SR2)

    I have a routine which will create envelope(s) for any number of addresses on a document or letter. The only requirement is that the address(es) be enclosed in a bookmark. If that is of interest, see post 55771 (sorry, I don't know how to put a link to it inside this message).

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    >only requirement is that the address(es) be enclosed in a bookmark

    hah! I got rid of that requirement with my EnvelopeFromSelection. The code is smart enough to locate the block of address from the selection, even if it is a single character selection.

    I have now drafted my first version of the address snatcher. There are many ways to do it. Ultimately I'd like a heuristic process; before that I'll have different rules for syntax and lexical items embedded in tables (so the user can change them). Weighting rules for scoring would be good. make several attempts then choose the highest score. First off is a very crude thing - looks for a postal code (canadian "A9A 9A9") and works backwards and forwards from there.

    My aim is to be able to capture a web page and extract all the names and addersses with one click.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    > As far a a discussion goes, I don't recall.

    I must be halucinating again. Is it a weekday?


    I *swear* that there was a long discussion (in which I did not take part, so it wasn't a long rambling discussion) about the types of postal codes.

    Not to worry. I have sketched out a scheme for detecting address components from a text stream. It is table-driven (controlled therefore by the user) so that one could change the postal code or telephone format definitions, or add extra ones.

  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: A Better Envelope Dialog (97 SR2)

    Well, <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=vb&Number=59923&page=&v iew=&sb=&o=&vc=1#Post59923>here is a short discussion </A> on the subject. Other than that...

    I have a question for you, but not on this topic, so look for another post titled "Text Processor".
    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
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    Thanks. That and Brooke's "missing link" was what I remebered. I have copied the posts to my hard drive.

    What I need now is a means to grab all the email posts and re-format them to a nice document format .....




    >look for another post titled "Text Processor".

    OK. I've done that. Now you do your homework. I want a full report on my desk by 9am tomorrow, new York time (grin!)

  11. #11
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    <hr>Brooke's a "missing link"<hr>
    <hr>Brooke's "missing a link"<hr>
    just what are you saying here, Chris? <vbg>

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Better Envelope Dialog (97 SR2)

    Oh! There you are! Well, if you're here, you're not missing, so it must mean that ...

Posting Permissions

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