[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

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

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 ' " '.

Example:
Original:
SCOLOAN.SEGMENT as SEGMENT_ID,
Desired:
sQuery = sQuery & ", SCOLOAN.SEGMENT as SEGMENT_ID  "
0
Cook09
Asked:
Cook09
  • 2
1 Solution
 
Patrick MatthewsCommented:
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:

,^p

Repeat until no more instances are found.

2) Now, use Find/Replace to find:

,^p

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.
0
 
Cook09Author Commented:
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.
QueryFormatting.docx
0
 
Cook09Author Commented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now