Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2013, 07:44 AM
sleake sleake is offline Error in Macro to Add 2 Spaces After Closing Parenthesis Windows XP Error in Macro to Add 2 Spaces After Closing Parenthesis Office 2007
Advanced Beginner
Error in Macro to Add 2 Spaces After Closing Parenthesis
 
Join Date: Jul 2011
Posts: 60
sleake is on a distinguished road
Default Error in Macro to Add 2 Spaces After Closing Parenthesis

Upper management on my project has directed us to use two spaces after periods (next they'll be re-issuing IBM Selectrics!).

I've created a macro to add 2 spaces after periods and colons. But now need to create one that adds 2 spaces after a closing parenthesis within a paragraph. For example, if there is a (See Section X.) within a paragraph -- not at the end.



I recorded a macro using Replace, which worked when I recorded it, but gives a "The Find What text contains a Pattern Match expression which is not valid." I'm sure it's the ), but don't know what to do to omake the macro do what I want. Here's the recorded code:

'Places 2 spaces after a closing parenthesis ")" within lines of text
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ") "
.Replacement.Text = ") "
.Forward = True
.Wrap = wdFindContinue

End With
Selection.Find.Execute Replace:=wdReplaceAll

I'd appreciate suggestions.
Reply With Quote
  #2  
Old 09-15-2013, 02:41 PM
Charles Kenyon Charles Kenyon is offline Error in Macro to Add 2 Spaces After Closing Parenthesis Windows Vista Error in Macro to Add 2 Spaces After Closing Parenthesis Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,464
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Sorry, don't know the answer to your direct question.

I am sure that this will give you multiple spaces (more than two) when run more than once. Before running these on a document where someone may have put in the two spaces already you need to run another macro that gets rid of two spaces (or three, four, or five) in a row.

If there will always be a period before the ) when you want to do this, you should code for that. i.e. find ".) " and replace with ".) "

Any chance you have wild cards turned on?
Reply With Quote
  #3  
Old 09-16-2013, 04:54 AM
sleake sleake is offline Error in Macro to Add 2 Spaces After Closing Parenthesis Windows XP Error in Macro to Add 2 Spaces After Closing Parenthesis Office 2007
Advanced Beginner
Error in Macro to Add 2 Spaces After Closing Parenthesis
 
Join Date: Jul 2011
Posts: 60
sleake is on a distinguished road
Default Error in Macro to Add 2 Spaces After Closing Parenthesis

I've tried it with and without Wildcards. Present test version is without. I made the change you suggested -- .) -- because it would (should) always have a period. Good point about two spaces.

Unfortunately, I get the same error. I think we editors will need to do this manually doing a Find/Find Next (in case of two spaces) -- it works using the Replace command -- just not when it's in macro form.

I do have a macro (being "retired") to search for more than one space and replace with one after periods and colons. So I can keep that one for occasional use. Now I have a new one to search for 3 or more spaces and replace with 2 after periods and colons. We'll just have to do the .) manually.

Appreciate your response.
Reply With Quote
Reply

Tags
problem with macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple VBA macro error Formulayeti PowerPoint 1 12-09-2011 10:02 PM
Error in Macro to Add 2 Spaces After Closing Parenthesis Why it works but the macro is error in VB? tinfanide Excel Programming 5 12-03-2011 12:53 AM
Macro Error 5174 muster36 Word VBA 0 08-12-2011 03:34 AM
Word doc bug when closing from userform command button click macro Joe Patrick Word 1 07-05-2011 08:53 PM
Error On Closing Program - Outlook 2000 sheepy11 Outlook 0 01-08-2006 08:39 AM

Other Forums: Access Forums

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