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

    Re: Extract Addess (Word 2002/SP2)

    > extract the inside address of a letter

    I'm not sure what you mean by this.

    I have written code that can parse text (for example, news paper stories) and locate street addresses.
    I have written macros that operate on selected text and build envelopes.

    Once you have an address, are you able to build the envelope?

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Addess (Word 2002/SP2)

    I want to use code that functions like the built-in envelopes and labels tool. When you click the button, Word finds the inside address of the letter without having to select it. I am then going to take the address and display it in a dialogue box that I will build and give users the options to print or add to document. I am doing this separately because a graphic artist designed a new logo so now I have a custom size label to print in addition to printing envelopes. I will have envelopes in the env feeder and labels in tray 1. I don't want the users to have to switch between trays when deciding between a label and an envelope.

  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: Extract Addess (Word 2002/SP2)

    OK. I'm lost.

    I see nothing in (wordXP) Tools, Letters and mailings, Envelopes and mailings that suggests Word will locate the address block.

    I'm using a letter with the text cursor sitting to the left of the first character of the address, in order to give Word a broad hint, but Word does not load that address into my envelope dialogue box.

    If I pre-select the address, then that address is pre-loaded, but so is any text I happen to select - nothing especial about an address.

    Are you sure that Word is smart enough to locate the address in your document? If you are seeing a pre-loaded address, is it perhaps being brought in from a current Outlook or Exchange file?

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Addess (Word 2002/SP2)

    In all versions of Word I can remember, Word has been smart enough to locate the inside address and load it into the Envelopes and Labels dialogue without selecting. The only exception I have found is if the inside address is actually using fields instead of just straight typed text.

    Nonetheless, this code is working for me ...

    Application.ScreenUpdating = False
    ActiveDocument.Envelope.Insert extractaddress:=True, omitreturnaddress:=True
    strAddress = ActiveDocument.Envelope.Address
    ActiveDocument.Undo 1
    Application.ScreenUpdating = True

    It adds the address to the document w/ screen updating off, then uses the envelope address of the document to store to the variable.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Extract Address (Word 2002/SP2)

    This seems like it should be easy, but I can't seem to figure it out.

    I am want extract the inside address of a letter to populate/print another document based on a custom template. I can not figure out how to extract this address. I have been playing with the build-in wdDialogToolsCreateEnvelope, but how can I extract the inside address to store it to a variable?

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

    Re: Extract Addess (Word 2002/SP2)

    > Word has been smart enough to locate the inside address

    Not for me. I have attached a small document with a simple chunk of code in a VBA module. The document text was pasted via Notepad.

    No fields. One image.

    I place my text cursor with Ctrl-Home and run the macro. Nada in strText.

    Help About tells me I'm using v 2002.

    I see nothing in Tools, Options that might thwart address extraction.

  7. #7
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Extract Addess (Word 2002/SP2)

    In your document, I changed the paragraph formatting so space before and space after are 0, then Word found the address.

  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: Extract Addess (Word 2002/SP2)

    > space before and space after are 0

    Darryl, thanks.

    Touchy little beast, isn't it? After setting before/after to zero, I saw the Tools, Letters & mailings; Envelopes & mailings work.
    Then I saw your code snippet work

    But your .Show method remains sterile. I'd sure like to see something work.

    FWIW you now have two exceptions rather than one ("if the inside address is actually using fields").

    The code below will obtain the address, but at the expense of playing around with your document (which will now be "dirtied")

    <pre>Public Function strAddress(doc As Document) As String
    '
    ' Macro1 Macro
    ' Macro recorded 1/12/2005 by Chris Greaves
    '
    doc.Envelope.Insert ExtractAddress:=True
    Dim rng As Range
    Set rng = doc.Sections(1).Range
    strAddress = rng.Text
    rng.Delete
    End Function
    Sub TESTstrAddress()
    MsgBox strAddress(ActiveDocument)
    End Sub</pre>


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

    Re: Extract Addess (Word 2002/SP2)

    Here's some more results from playing around:

    An address block must be less than five paragraphs
    An address block must be more than two paragraphs
    If two or more suitable paragraph sets are found, the latest one will be prefererd
    An 18 word block is prefererd over a 12 word block
    A 4-line 25-word block is prefered over an earlier 3-line 12-word block.

    (attached a new sample with macros Test4 and TESTstrGrabAddress)

Posting Permissions

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