Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2019, 07:54 AM
Alsadius Alsadius is offline Deleting text but keeping adjacent spaces Windows 7 64bit Deleting text but keeping adjacent spaces Office 2010 32bit
Novice
Deleting text but keeping adjacent spaces
 
Join Date: Nov 2017
Posts: 25
Alsadius is on a distinguished road
Default



Quote:
Originally Posted by macropod View Post
Why not just use a Find/Replace?
The biggest reason is that I'd need to refactor a ton of code to make it work that way, and do so in a way inconsistent with the rest of my code. Normally I'd just do that, but in context of the whole project it's a lot more work than it sounds like.

My hope is that there's a simple flag I can use for "Don't delete adjacent spaces" - I think I've seen info about how to set that in Word option menus, but I can't find anything about doing it in VBA code.

EDIT: Never mind, figured it out. If I replace VarRange.Delete with VarRange.Text = "" then it works fine. It seems like the adjacent space cleanup only applies when the .Delete procedure is run, and any other method of deleting it will leave the spaces.
Reply With Quote
  #2  
Old 03-01-2019, 01:39 PM
macropod's Avatar
macropod macropod is offline Deleting text but keeping adjacent spaces Windows 7 64bit Deleting text but keeping adjacent spaces Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,516
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Alsadius View Post
The biggest reason is that I'd need to refactor a ton of code to make it work that way
I hardly think so. It could all be done with a single line of code:
Code:
Selection.Find.Execute "<Replace Me>", , , False, , , True, wdFindStop, , "New Text", wdReplaceOne
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-04-2019, 06:56 AM
Alsadius Alsadius is offline Deleting text but keeping adjacent spaces Windows 7 64bit Deleting text but keeping adjacent spaces Office 2010 32bit
Novice
Deleting text but keeping adjacent spaces
 
Join Date: Nov 2017
Posts: 25
Alsadius is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
I hardly think so. It could all be done with a single line of code:
Code:
Selection.Find.Execute "<Replace Me>", , , False, , , True, wdFindStop, , "New Text", wdReplaceOne
I hardly think so. The deletion and replacement are in separate subs, each of which spends a lot of lines of code figuring out what to delete/add, and it's done that way to stay consistent with significantly larger blocks of code elsewhere in the macro. I'd have to re-arrange a goodly part of my program to do it the way you suggest. When I'm demoing this to senior management this week and want it to run perfectly, and when the program as a whole has shown a fondness for subtle bugs.

I posted a stripped-down sample sub in this thread, but don't confuse that with the actual program I'm working on.
Reply With Quote
  #4  
Old 03-04-2019, 02:06 PM
macropod's Avatar
macropod macropod is offline Deleting text but keeping adjacent spaces Windows 7 64bit Deleting text but keeping adjacent spaces Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,516
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Alsadius View Post
I hardly think so. The deletion and replacement are in separate subs, each of which spends a lot of lines of code figuring out what to delete/add, and it's done that way to stay consistent with significantly larger blocks of code elsewhere in the macro.
You can, of course, pass the Find & Replace strings to that line as arguments... But, hey, if you don't want to improve your code, who am I to argue!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I stop check boxes moving rows when text wraps in an adjacent cell? PatrickYork Excel 2 04-04-2018 11:23 AM
Big Spaces/pages between text tissueboxer Word 6 03-03-2018 07:52 AM
Vertical Text Alignment with Adjacent Columns kdutrisac Word Tables 2 06-26-2017 12:38 PM
Deleting grid lines but keeping the axis lines CoffeeNut Excel 0 04-01-2013 01:50 PM
Conditional Formatting Expiration Dates Based on Text in Adjacent Cell Frogggg Excel 1 10-25-2011 08:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:51 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