#1
|
|||
|
|||
VBA Quotes Before Punctuation
I am trying to move quotes before punctuation with a Word macro, but apart from an error in the code here below, I cannot find a way to swap characters without using 'Selection.' Can someone help? Thanks! Here's the code:
Quote:
Last edited by RobiNew; 09-23-2023 at 07:24 AM. Reason: typo |
#2
|
|||
|
|||
Hi, if I correctly understand your objective, try this (move quotes to be just before the punctuations):
For Each myChr In myRng.Characters If myChr Like "[,;.:?]" _ And myChr.Next Like "[«‹›»" & Chr(39) & Chr(34) & Chr(146) & Chr(148) & "]" Then myChr.InsertBefore myChr.Next myChr.Next.Delete End If Note that the code is quite slow because it checks each char in the range. |
#3
|
|||
|
|||
Thanks a lot for your help! Now the macro does its job correctly, but before closing it shows a message of the type "Object variable or variable of the With block not defined" and highlights the following lines of the code:
Quote:
|
#4
|
|||
|
|||
I didn't check this on footnotes, but it's much faster:
For Each myRng In ActiveDocument.StoryRanges Do With myRng Do With .Find .MatchWildcards = True .text = "[,;.:?]" & "[«‹›»" & Chr(39) & Chr(34) & Chr(146) & Chr(148) & "]" .Replacement.text = "" .Wrap = wdFindStop .Execute End With If .Find.found Then myRng.InsertBefore myRng.Characters.Last myRng.Characters.Last.Delete Else: Exit Do End If myRng.Collapse 0 Loop End With Set myRng = myRng.NextStoryRange Loop Until myRng Is Nothing Next myRng |
#5
|
|||
|
|||
It is indeed much faster. And it works also in the footnotes. I think it's perfect. Many, many thanks!
|
#6
|
|||
|
|||
I am glad I managed to help you!
|
Tags |
characters, quotes, swap |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem when changing single-quotes to double-quotes | Lup | Word | 14 | 02-14-2020 02:46 AM |
Curly Smart Quotes Switch to Straight Smart Quotes in New Chapters | TheWriterBloke | Word | 3 | 03-29-2019 03:11 AM |
How to replace straight quotes with smart quotes in existing document | PABwriter | Word | 4 | 05-27-2016 03:36 PM |
Changing dumb quotes to smart quotes | Reisende | Word | 2 | 05-02-2016 08:56 PM |
Changing single-quotes to double-quotes | Bobosmite | Word | 5 | 04-15-2013 06:40 AM |