Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-19-2014, 03:06 PM
Marrick13 Marrick13 is offline Insert space before and after target text Windows XP Insert space before and after target text Office 2010 32bit
Competent Performer
Insert space before and after target text
 
Join Date: Jun 2006
Posts: 102
Marrick13 will become famous soon enough
Default Insert space before and after target text

The “Replace” macro was based on Macropod’s code from “Conditional tied to trying to find a " " space character” (https://www.msofficeforums.com/word-...character.html), which I adopted for a slightly different purpose. That purpose is to search for text entered in an input box in Word and test the character immediately in front of and following the target text. If it is not a space, enter a space, otherwise, ignore.

The Replace macro inserts a space in the front of the target. I added a variation so that the macro also inserts a space after the target text. Both work well except:

1. If the target is at the beginning of a sentence following a blank row.
2. If the target text’s case contains any upper case letters.

The case sensitivity is puzzling, especially when I’ve tried to shut it off on the code using MatchCase:=False and Option Compare Text. I want it to ignore case altogether.

The other effect I want is for the macro to read certain characters that follow the target text and if found, desist from inserting a space. I tried this by setting the characters below to the CharName variable and adding the Instr statement to see if it does the job, but it doesn’t work.

CharName = ",.?/\¬`!£$%^&*-+='@#~:;|<>¦-_{}[]()`¬'"

If InStr(1, CharName, SearchText) = 0 Then
.InsertAfter " "



I’ve attached a short Word doc with text for testing (highlighted in yellow) and a text file containing the macro (for some reason, this site no longer allows a .docm type file to be attached). If anybody has any suggestions for making it work as described above, please let me know. Thank you.
Attached Files
File Type: docx TEST of Insert Space Macro (2).docx (22.4 KB, 16 views)
File Type: txt InsertSpaceBeforeandAfterText Code.txt (4.9 KB, 15 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert space before and after target text macro to find a character and insert space so autocorrect will expand redzan Word VBA 3 05-22-2014 04:22 PM
Insert space in front of a numberd list MS Word ekesawi Word 1 12-05-2012 07:21 PM
Insert space before and after target text Envelope Printing is off target - need help please! mylan Word 2 10-24-2012 12:24 PM
Send OFT when target email arrives RandWald Outlook 0 11-11-2011 10:52 AM
Insert space before and after target text Target line on a excel graph leroytrolley Excel 1 01-16-2009 04:19 PM

Other Forums: Access Forums

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