Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2025, 02:10 AM
RobiNew RobiNew is offline Replacing question mark plus wrong angle quotation mark Windows 11 Replacing question mark plus wrong angle quotation mark Office 2016
Competent Performer
Replacing question mark plus wrong angle quotation mark
 
Join Date: Sep 2023
Posts: 225
RobiNew is on a distinguished road
Default Replacing question mark plus wrong angle quotation mark

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
Reply With Quote
  #2  
Old 11-17-2025, 04:04 AM
gmaxey gmaxey is offline Replacing question mark plus wrong angle quotation mark Windows 10 Replacing question mark plus wrong angle quotation mark Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,634
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-17-2025, 04:34 AM
RobiNew RobiNew is offline Replacing question mark plus wrong angle quotation mark Windows 11 Replacing question mark plus wrong angle quotation mark Office 2016
Competent Performer
Replacing question mark plus wrong angle quotation mark
 
Join Date: Sep 2023
Posts: 225
RobiNew is on a distinguished road
Default

Thank you! But I cannot understand your double replacing and in any case the result is always the wrong "«»".
Reply With Quote
  #4  
Old 11-17-2025, 06:13 AM
gmaxey gmaxey is offline Replacing question mark plus wrong angle quotation mark Windows 10 Replacing question mark plus wrong angle quotation mark Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,634
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 11-17-2025 at 08:50 AM.
Reply With Quote
  #5  
Old 11-17-2025, 07:29 AM
RobiNew RobiNew is offline Replacing question mark plus wrong angle quotation mark Windows 11 Replacing question mark plus wrong angle quotation mark Office 2016
Competent Performer
Replacing question mark plus wrong angle quotation mark
 
Join Date: Sep 2023
Posts: 225
RobiNew is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 11-17-2025, 08:50 AM
gmaxey gmaxey is offline Replacing question mark plus wrong angle quotation mark Windows 10 Replacing question mark plus wrong angle quotation mark Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,634
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 11-17-2025, 09:38 AM
RobiNew RobiNew is offline Replacing question mark plus wrong angle quotation mark Windows 11 Replacing question mark plus wrong angle quotation mark Office 2016
Competent Performer
Replacing question mark plus wrong angle quotation mark
 
Join Date: Sep 2023
Posts: 225
RobiNew is on a distinguished road
Default

Many thanks, gmaxey! Now it is all OK. All the best!
Reply With Quote
Reply

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
Replacing question mark plus wrong angle quotation mark Symbol in heading showing as question mark using StyleRef NU2word Word 2 11-04-2022 10:12 AM
Replacing question mark plus wrong angle quotation mark Em dash and closing curly quotation mark lexsper Word 3 04-07-2015 07:12 AM
Replacing question mark plus wrong angle quotation mark Upside Down Question Mark? dsfcom Word 3 10-07-2011 05:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft