0
votes

I am working on a migration project for my organization which transitions our staff from the Word Perfect Office suite to Microsoft Office, specifically WordPerfect to Word. Unfortunately there is a very heavy reliance on macros in word that just don't transfer to Word. While progress is being made in steps, I have hit road blocks that I am not sure I can overcome with vba, macros or regex especially since I am far from proficient with any of them.

  1. There is a very heavily used formal letter template that gets created to send to external contacts. It is usually the first or second step in adding a new client into our systems for services. In this letter a secretary adds an autotext entry at the top of the page followed by several enter keystrokes. Immediately below that, anywhere from 1 to 3 or 4 addresses are added in the format similar to below:

    Letter Head block of Primary account handler (inserted by autotext)
    (Multiple Blank Lines)
    
    (blank line)(Each line of address is ended with the enter keystroke)
    
    1st Company Name (If exists)(Sometimes includes right-align tabstop for email)
    Attn to or Individual
    Street Address
    Suite or Apt # (If exists)
    City, State, ZIP-#### (The zip extension is not always included)
    
    (blank line)
    
    2nd Company Name (If exists)(Sometimes includes right-align tabstop for email)
    Attn to or Individual
    Street Address
    Suite or Apt # (If exists)
    City, State, ZIP-#### (The zip extension is not always included)
    
    (blank line)
    3rd Address Block and so on...
    
    (blank line)
    (blank line)
    Dear, Primary Addressee of Letter
    

Since this letter is more or less the start of a process, it contains data that needs to be used one or twice more. Currently in word I can go to Mailings > Envelopes and bring up the window that sometimes pulls the first address from the document. It does not always pull the entire address block as entered and once the first envelope is printed. The user must manually copy and paste the remaining address blocks one at a time into a new Envelopes and Lables box. Our envelopes are pre-printed and only need to contain the individual addresses from the letter.

What I would like to try to do is any of the following options or a combination of them:

  1. Allow the user to manually highlight the text, trigger a macro opens a new document based on a template with the selected text pasted in. I would also be happy with opening a new blank document if I can define the margins and other page setup properties as it is created and then paste in the selected address block. I am only aware of using "Documents.Add Template:="path to template" for opening a new document based on template. I am not sure how to paste the pass the highlighted text through.

  2. Create a regex pattern that can identify and select each address following the blank line through the zip code. I was able to find a regex pattern that would identify the zip code and optional 4 digit number that follows which is

    (\d{5}(-\d{4})?)
    

    I am not sure how I can expand the range to include all the lines of information preceding the zip code using the blank line as the boundary though.

  3. The icing on the cake for me would be to use the regex pattern to find each address block and then run a loop to open the new document with defined properties or new document based on template and then insert each address with a page break at the end. The very last address should not have the page break though.

If anyone is able to help me figure this out I would be more than happy to thank you by way of donation to your cause or to an organization on your behalf. Programming has never been my strong suit and this challenge has kept me awake at night trying to figure it out.

1

1 Answers

0
votes

This is a very broad question -- probably too broad for SO.
For item #2, how about
(\r\r.+\d{5}(-\d{4})?)