PDA

View Full Version : Quotation marks



Lucy234
03-16-2012, 10:50 AM
How to make a space between a quotation mark and every letter in the text? Characters like /,.( are excluded.
Winter is nice"but it's not" / Winter is nice "but it's not"

Talis
03-16-2012, 11:51 AM
Find: ([A-z])(["“][A-z])
Repl: \1 \2

Notes: Check 'Use wildcards'. The central square brackets ["“] hold both a plain double quote and a curly opening quote. There is a space between \1 \2.

Lucy234
03-16-2012, 10:58 PM
Find: ([A-z])(["“][A-z])
Repl: \1 \2

Notes: Check 'Use wildcards'. The central square brackets ["“] hold both a plain double quote and a curly opening quote. There is a space between \1 \2.

Not good because it does the following:

Winter is nice"but it's not"really becomes
Winter is nice "but it's not "really.

I need the quoted text to have always one space from the left and right, so if there is a text reclining to the quotation marks on the right, there should be one space field put between them. Same goes for the left one as well.

BoatwrenchV8
03-16-2012, 11:43 PM
I am sure this is not the best way but it will work (at least it did for me). The macro will do 2 quotations marks (one set of quotes) at at time. Again, this is not the only way to do this or the best way.


Sub Lucy234QuotationMarksV1()
'
'
' Finds and replaces the first occurance
' of character"character and replaces it
' with character "character and then finds
' the second instance of character"character and
' replaces it with character" character.
'
' If either the first or the second instance
' are not found, a message box is diplayed
' and the macro ends.
'
'***IMPORTANT***
'Start this macro with the insertion point/cursor
' at the very top of the text you want to be
' changed. This macro must start from the top
' and work towards the bottom.
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([A-z])([""" & ChrW(8220) & "])([A-z])"
.Replacement.Text = "\1 \2\3"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.Collapse direction:=wdCollapseEnd

If Selection.Find.Found = False Then
MsgBox "First instance of quotation mark not found. Stopping macro."
Exit Sub
End If

With Selection.Find
.Text = "([A-z])([""" & ChrW(8220) & "])([A-z])"
.Replacement.Text = "\1\2 \3"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.Collapse direction:=wdCollapseEnd

If Selection.Find.Found = False Then
MsgBox "Second instance of quotation mark not found. Stopping macro."
Exit Sub
End If

End Sub



This is the Before and After:

Before macro
Winter Is nice"but it's not"really becomes... Winter Is nice"but it's not"really becomes... Winter Is nice"but it's not"really becomes...
After macro
Winter Is nice "but it's not" really becomes... Winter Is nice "but it's not" really becomes... Winter Is nice "but it's not" really becomes...

Talis
03-16-2012, 11:52 PM
You've changed what you asked for!
In your original example where is the word "really"? You didn't specify that the closing quotation mark could be immediately followed by a letter.

I suggest you learn about converting plain quotes to curly quotes:
Tools > Autocorrect Options > Autoformat As You Type > "Straight quotes" with "smart quotes".
Then a Find/Replace of a double quote for the same double quote.

It would then be a good opportunity for you to do a bit of work for yourself modifying the Find/Replace I provided into two Find/Replaces to operate on first the opening quotes and then secondly on the closing quotes.

If you do that and show your efforts here I will show you how it can be done with a single Find/Replace. Hopefully no one will defeat the purpose of this exercise by providing you with the answer with no effort on your part.

Edit: BoatwrenchV8 sent his response whilst I typed mine.

Lucy234
03-17-2012, 10:06 AM
Ty Boatwrench, works like a charm. That's Exactly what I was looking for.

Lucy234
03-17-2012, 10:07 AM
Thx for trying Talis.

BoatwrenchV8
03-17-2012, 10:42 AM
Ty Boatwrench, works like a charm. That's Exactly what I was looking for.


You're welcome. Happy it works for you. I suggest you step thru it and see how it works.

macropod
03-17-2012, 02:51 PM
You've changed what you asked for!
Lucy has a habit of doing this - and not providing full details of the requirements, then complaining the solution doesn't work (and not saying why).:banghead:

BoatwrenchV8
03-17-2012, 03:17 PM
I just did a little research and completely understand what you and others are saying after reading some of the other posts. Hopefully, any future posts for assistance will be clearer and more complete.

Lucy234
03-18-2012, 05:36 AM
Lucy has a habit of doing this - and not providing full details of the requirements, then complaining the solution doesn't work (and not saying why).:banghead:

I did explain why it didn't work. Someone obviously understood what I needed and I got it. I assume Talis knew from the start what I wanted, he just wanted to show his domination by using sarcasm and pretending ignorance.

fumei
03-18-2012, 10:59 PM
No you did not explain why, at least not until your first incomplete postings did not fulfill your unstated requests. And using words like domination and "pretending ignorance" just shows again that you really do not belong here. You are rude and offensive and arrogantly assuming your pathetic attempts causes some sort of mind-reading on the part of others.

I am formally asking that you be removed from this forum. You are disrupting things while contributing nothing.

Talis
03-19-2012, 10:41 AM
Just in case someone has come to this thread needing help with quotation marks here's a subroutine to convert quotes:
Sub replace_quotes()
Dim bool As Boolean
Dim Rng As Range

'Get state
bool = Options.AutoFormatReplaceQuotes

Options.AutoFormatAsYouTypeReplaceQuotes = True
Set Rng = ActiveDocument.Range

With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = """"
.Replacement.Text = """"
.Execute Replace:=wdReplaceAll, Wrap:=wdFindContinue
End With

'Return state
Options.AutoFormatAsYouTypeReplaceQuotes = bool
End Sub

Note:
For single quotes change the Find and Replace strings to:


.Text = "'"
.Replacement.Text = "'"

Test text:


The quick brown fox jumps over the lazy dog. "The quick brown ‘fox’ jumps over the lazy dog."
"The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog."
O'Brien's dog was called 'Rover' .

To find Left Double Quotes now use:
Find: Chr(147)
To find Right Double Quotes use:
Find: Chr(148)
Similarly Single quotes are: Chr(145) and Chr(146)