Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2016, 04:30 PM
Guessed's Avatar
Guessed Guessed is offline Detecting that previous character doesn't exist (i.e., present character is first in document) Windows 10 Detecting that previous character doesn't exist (i.e., present character is first in document) Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Unfortunately, with the wonder of hindsight, just about everybodies code could be improved once its been created. Looping through every character is horrendously slow and it appears you are probably doing this more than once so that magnifies it.

It might be worth taking a step back and looking at your requirements once again to see how to make the code really efficient. I would recommend getting away from Selections and strings in favour of ranges.

For the job you describe here it would be WAY faster to do find/replaces instead of looping characters.


eg with wildcards on find "([! ])\[\[" and replace with "\1 [[" to ensure there is always a space in front of any opening double square brackets
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 07-20-2016, 05:02 AM
Robert K S Robert K S is offline Detecting that previous character doesn't exist (i.e., present character is first in document) Windows 7 64bit Detecting that previous character doesn't exist (i.e., present character is first in document) Office 2007
Novice
Detecting that previous character doesn't exist (i.e., present character is first in document)
 
Join Date: Jul 2016
Location: Cleveland, Ohio
Posts: 10
Robert K S is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
For the job you describe here it would be WAY faster to do find/replaces instead of looping characters.
eg with wildcards on find "([! ])\[\[" and replace with "\1 [[" to ensure there is always a space in front of any opening double square brackets
That's great advice. Thank you!

EDIT: but it adds a space between deleted content and punctuation outside the deleted content, so I might end up with, for example, [[4]] , instead of [[4]], which is what is desired.

Maybe a cheap fix would be to only add whitespace (where it doesn't exist) between underlined text and [[, or between ]] and underlined text? That way it would at least fix [[this]]sort of thing when [[this]] sort of thing is desired.

Last edited by Robert K S; 07-20-2016 at 07:55 AM.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting that previous character doesn't exist (i.e., present character is first in document) Macro to list all character styles in a document ljd108 Word VBA 11 08-28-2024 01:20 AM
Detecting that previous character doesn't exist (i.e., present character is first in document) Replace a random character with the same character RickLegrand Word 7 07-23-2015 06:35 PM
Detecting that previous character doesn't exist (i.e., present character is first in document) How can select from a specific character to another character mohsen.amiri Word 2 02-19-2015 11:38 PM
Detecting that previous character doesn't exist (i.e., present character is first in document) Regular (roman) character style doesn't change text to roman kcbenson Word 2 10-16-2014 01:31 PM
Detecting that previous character doesn't exist (i.e., present character is first in document) Finding or searching ^ character in word document shahin3121 Word 2 03-05-2012 06:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:08 PM.


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