Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-28-2019, 02:48 PM
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 Deleting text but keeping adjacent spaces

I'm doing a text replacement macro that deletes text in one sub, and then has another sub insert different text into the same spot. However, when I delete text and there's a space on either side, Word's default text deletion will eliminate one of the spaces, which means that the inserted text is now lacking a space between it and an adjacent word. It's also messing up formatting when highlighting changes at the same spot.

Original text: Intro <Replace Me> More

Sub Test()


Dim VarRange As Range
SelectText ("<Replace Me>")
Set VarRange = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End)
VarRange.Delete
Selection.InsertAfter ("New Text")
End Sub

Should produce: Intro New Text More
Actually produces: Intro New TextMore

What I'd like is a flag I can set to make it not delete adjacent spaces, but all my searching hasn't shown me one. I know of a couple hacky workarounds that I can use if need be - find-and-replace, in particular - but because of the structure of the code, doing it that way would make the overall program much more complex.

Thanks.
Reply With Quote
 



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 05:00 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