Dudes,
I would like to have a Word macro that can wrap quotes around each line of
selected text, followed by a comma at the end of each line. Preferably it
won't append a comma to the last line, but I'll settle for a solution
without this extra feature.
eg.
Dog
Cat
Fish
Bird
becomes
'Dog',
'Cat',
'Fish',
'Bird'
The reason I need this is to allow me to save a lot of time where I have to
manually create an SQL query that includes a long list of search criteria.
Thanks. The first to provide a solution goes to the top of the class!
Poster
Jean-Guy Marcil - 28 Jun 2004 03:22 GMT
Bonjour,
Dans son message, < Poster > ?crivait :
In this message, < Poster > wrote:
|| Dudes,
||
|| I would like to have a Word macro that can wrap quotes around each line
of
|| selected text, followed by a comma at the end of each line. Preferably it
|| won't append a comma to the last line, but I'll settle for a solution
[quoted text clipped - 13 lines]
|| 'Fish',
|| 'Bird'
Dealing with lines in Word can be tricky as they do not really exists as
objects in the VBA model (Neither do pages).
Are these one-word line as in your examples? Are you talking about
paragraphs with wrapped lines? Was "Enter" hit to end each line?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Jezebel - 28 Jun 2004 03:30 GMT
Assuming that each of your lines is a single-word paragraph, you can simply
use Find and Replace, manually or via VBA. With 'Use wildcards' checked,
search for
<([!^13]*)^13
and replace with
"\1",^p
You'll have to delete the final comma by hand.
> Dudes,
>
[quoted text clipped - 23 lines]
>
> Poster
Jay Freedman - 28 Jun 2004 04:14 GMT
Assuming the words are separated by paragraph marks (¶) and not manual
line breaks, this macro will do the job.
Sub AddQuoteComma()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(<[!^13]{1,})^13"
.Replacement.Text = "'\1',^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
'remove final comma and paragraph mark
Set oRg = ActiveDocument.Range
With oRg
.Collapse wdCollapseEnd
.MoveStartUntil cset:=",", Count:=wdBackward
.MoveStart unit:=wdCharacter, Count:=-1
.Delete
End With
Set oRg = Nothing
End Sub
>Dudes,
>
[quoted text clipped - 23 lines]
>
>Poster
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word
Poster - 29 Jun 2004 09:36 GMT
Jay Freedman wrote in message ...
>Assuming the words are separated by paragraph marks (?) and not manual
>line breaks, this macro will do the job.
[quoted text clipped - 26 lines]
> Set oRg = Nothing
>End Sub
Wow, very impressive. Thank you.
Poster - 30 Jun 2004 09:30 GMT
The only remaining problem is that when the resulting text is pasted into a
Query Analyzer session, Query Analyzer doesn't recognise the apostrophes and
so an error occurs when trying to run an SQL query. It seems that an
apostrophe in Word is different to an apostrophe in Query Analyzer. Would
any of you Microsoft guys ever have encountered this problem before?
Jay Freedman wrote in message ...
>Assuming the words are separated by paragraph marks (?) and not manual
>line breaks, this macro will do the job.
[quoted text clipped - 59 lines]
>Jay Freedman
>Microsoft Word MVP FAQ: http://www.mvps.org/word
Jay Freedman - 30 Jun 2004 17:45 GMT
Hi Poster,
Do your queries contain "curly quotes" that curve in opposite directions at
the start and end of each word? If so, that's why Query Analyzer doesn't
recognize them -- they're actually different characters than the "straight
quote"/apostrophe.
To fix it up, first go to Tools > AutoCorrect > AutoFormat As You Type.
Clear the option to replace "straight quotes" with "smart quotes". (Only MS
thinks they're smart!)
Now open the Replace dialog. Type one apostrophe in both the Find What box
and the Replace With box, and click the Replace All button. All the curly
quotes of both varieties will be replaced with straight quotes. Try the
result in Query Analyzer.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
> The only remaining problem is that when the resulting text is pasted
> into a Query Analyzer session, Query Analyzer doesn't recognise the
[quoted text clipped - 69 lines]
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://www.mvps.org/word