![]() |
|
|
|
#1
|
|||
|
|||
|
Hi! I need help to replace wrong "?«" with "?»", for the result is "«»". Here is the code:
Sub AngleQuotationMarks() Options.AutoFormatAsYouTypeReplaceQuotes = False For iType = 1 To 2 Set oRng = ActiveDocument.StoryRanges(iType) With oRng.Find .ClearFormatting .Replacement.ClearFormatting .Wrap = wdFindStop .Format = False .MatchWildcards = True .Text = "\?" & "(^0171)" 'to find ?« .Replacement.Text = "\1" & "^0187" 'to replace with ?» .Execute Replace:=wdReplaceAll End With Next iType End Sub |
|
#2
|
|||
|
|||
|
Code:
Sub AngleQuotationMarks()
Dim iType As Long
Dim oRng As Range
Options.AutoFormatAsYouTypeReplaceQuotes = False
For iType = 1 To 1 '2
On Error GoTo lbl_Exit
Set oRng = ActiveDocument.StoryRanges(iType)
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Text = "\?" & "(^0171)"
.Replacement.Text = "\1" & "^0187"
.Execute Replace:=wdReplaceAll
.Text = "\?" & "^0187"
.Replacement.Text = "^0171" & "^0187"
.Execute Replace:=wdReplaceAll
End With
Next iType
lbl_Exit:
'Options.AutoFormatAsYouTypeReplaceQuotes = True
Exit Sub
End Sub
|
|
#3
|
|||
|
|||
|
Thank you! But I cannot understand your double replacing and in any case the result is always the wrong "«»".
|
|
#4
|
|||
|
|||
|
I obviously don't understand what you are trying to achieve. What exactly is wrong and what exactly are your wanting to accomplish?
Perhaps: Code:
Sub AngleQuotationMarks()
Dim iType As Long
Dim oRng As Range
Options.AutoFormatAsYouTypeReplaceQuotes = False
For iType = 1 To 1 '2
On Error GoTo lbl_Exit
Set oRng = ActiveDocument.StoryRanges(iType)
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Text = "([! " & Chr(9) & Chr(11) & Chr(13) & Chr(160) & "])" & "(^0171)"
.Replacement.Text = "\1" & "^0187"
.Execute Replace:=wdReplaceAll
End With
Next iType
lbl_Exit:
'Options.AutoFormatAsYouTypeReplaceQuotes = True
Exit Sub
End Sub
Last edited by gmaxey; 11-17-2025 at 08:50 AM. |
|
#5
|
|||
|
|||
|
I have several instances of the type «Why?« that I want to change to «Why?». My code returns «Why«»
Sub AngleQuotationMarks() Options.AutoFormatAsYouTypeReplaceQuotes = False For iType = 1 To 2 Set oRng = ActiveDocument.StoryRanges(iType) With oRng.Find .ClearFormatting .Replacement.ClearFormatting .Wrap = wdFindStop .Format = False .MatchWildcards = True .Text = "\?" & "(^0171)" '(?«) .Replacement.Text = "\1" & "^0187" .Execute Replace:=wdReplaceAll End With Next iType End Sub |
|
#6
|
|||
|
|||
|
See my last reply.
But if it is as your last description (i.e., only after a literal question mark), then: Code:
Sub AngleQuotationMarks()
Dim iType As Long
Dim oRng As Range
Options.AutoFormatAsYouTypeReplaceQuotes = False
For iType = 1 To 1 '2
On Error GoTo lbl_Exit
Set oRng = ActiveDocument.StoryRanges(iType)
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Text = "(\?)" & "(^0171)"
.Replacement.Text = "\1" & "^0187"
.Execute Replace:=wdReplaceAll
End With
Next iType
lbl_Exit:
Options.AutoFormatAsYouTypeReplaceQuotes = True
Exit Sub
End Sub
|
|
#7
|
|||
|
|||
|
Many thanks, gmaxey! Now it is all OK. All the best!
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Picking up trailing space before quotation mark | WJSwanepoel | Word | 5 | 02-10-2025 01:31 PM |
| Trying to write a regular question mark with wildcards activated | frayfray96 | Word | 3 | 09-02-2023 08:21 AM |
Symbol in heading showing as question mark using StyleRef
|
NU2word | Word | 2 | 11-04-2022 10:12 AM |
Em dash and closing curly quotation mark
|
lexsper | Word | 3 | 04-07-2015 07:12 AM |
Upside Down Question Mark?
|
dsfcom | Word | 3 | 10-07-2011 05:57 AM |