VBA Sub to add, to each line, in a Word 2010 Document

Posted on 2012-09-18
Last Modified: 2012-09-25
I would like to be to have, in an active document, a statement added at the beginining of every line, regardless of whether there are Tabs or spaces. Then at the end of each line, deleting a "," adding a space, and then adding a ' " '.

sQuery = sQuery & ", SCOLOAN.SEGMENT as SEGMENT_ID  "
Question by:Cook09
    LVL 92

    Accepted Solution

    You can do this without any code.

    1) Use Find/Replace to find:

    ,_^p                       <--- use space instead of the underscore shown

    and replace that with:


    Repeat until no more instances are found.

    2) Now, use Find/Replace to find:


    and replace with:

    _"^psQuery = sQuery & ",_                <--- use spaces instead of the underscores shown

    3) You will probably have to manually adjust the very first and very last lines in the file.

    Author Comment

    Attached is a file that has the recommendations performed.  The other aspect is that this could be performed on serveral queries over time, and something a liitle automated might be better, given how this turned out.  The format is at it is to be sent the SQL Server, or very close to it, I just changed the names.  

    Below the end result, is a copy of the raw data in which I stripped a lot, but not all, of the nonprintable characters from the beginning.

    Author Closing Comment

    Come to find out, after the others, that I must have done something incorrect with this one, because it does work.  Should have done more beta with it.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now