PDA

View Full Version : Quotation marks



Snowflake
10-09-2012, 10:32 AM
Heya guys!

I was searching for a way to add or remove space after or before quotation marks in the sentence.

I found this

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 = wdFindContinue
.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 = wdFindContinue
.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


The problem is when I have a couple of quoted sentences, I have to copy-paste this 10-15 times cause it only works for one set of the quotation marks..:(

Oh well.

Hopefully you can help me here..

TY!

Snowflake
10-10-2012, 08:10 AM
Any ideas? :(

gmaxey
10-10-2012, 12:54 PM
Instead of trying to fix what doesn't work, what specifically are your trying to do?

Snowflake
10-11-2012, 10:15 AM
Instead of trying to fix what doesn't work, what specifically are your trying to do?

In sample 1 there is a text which shows how it looks like before the macro.

In sample 2 it shows how it's supposed to look like.

Snowflake
10-11-2012, 10:16 AM
The 2'nd part.

gmaxey
10-11-2012, 03:23 PM
Something like this might work:

Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim oRng As Word.Range
Dim lngCount As Long
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = """"
While .Execute
lngCount = lngCount + 1
Select Case lngCount Mod 2
Case 1
Do Until oRng.Characters.Last.Next <> " "
oRng.Characters.Last.Next.Delete
Loop
If oRng.Characters.First.Previous <> vbCr And oRng.Characters.First.Previous <> " " Then
oRng.InsertBefore " "
oRng.Collapse wdCollapseEnd
End If
Case Else
Do Until oRng.Characters.First.Previous <> " "
oRng.Characters.First.Previous.Delete
Loop
If Not oRng.Characters.Last.Next Like "[ .,?!]" Then
oRng.Text = oRng.Text & " "
oRng.Collapse wdCollapseEnd
End If
End Select
Wend
End With
End Sub


I think it will be pretty difficult to figure out if quotation marks are properly applied.

Snowflake
10-12-2012, 07:57 AM
Many many thanks!!! :grinhalo: