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

Re: Wrapping quotes around selected text by Jean-Guy

Jean-Guy
Sun Jun 27 21:22:00 CDT 2004

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
|| without this extra feature.
||
|| eg.
||
|| Dog
|| Cat
|| Fish
|| Bird
||
|| becomes
||
|| 'Dog',
|| 'Cat',
|| '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?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org




Re: Wrapping quotes around selected text by Jezebel

Jezebel
Sun Jun 27 21:30:45 CDT 2004

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.




"Poster" <Poster@hotmail.com> wrote in message
news:40dcdbb7$1_3@news.chariot.net.au...
> 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
>
>



Re: Help: Wrapping quotes around selected text by Jay

Jay
Sun Jun 27 22:14:23 CDT 2004

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


"Poster" <Poster@hotmail.com> 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
>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
>


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

Re: Help: Wrapping quotes around selected text by Poster

Poster
Tue Jun 29 03:36:09 CDT 2004


Jay Freedman wrote in message ...
>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
>

Wow, very impressive. Thank you.




Re: Help: Wrapping quotes around selected text by Poster

Poster
Wed Jun 30 03:30:16 CDT 2004

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.
>
>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
>
>
>"Poster" <Poster@hotmail.com> 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
>>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
>>
>
>
>--
>Regards,
>Jay Freedman
>Microsoft Word MVP FAQ: http://www.mvps.org/word



Re: Help: Wrapping quotes around selected text by Jay

Jay
Wed Jun 30 11:45:51 CDT 2004

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.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

Poster wrote:
> 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.
>>
>> 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
>>
>>
>> "Poster" <Poster@hotmail.com> 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 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
>>>
>>
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://www.mvps.org/word