Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2022, 12:45 PM
Ulodesk Ulodesk is offline Keeping a macro from going beyond selection Windows 10 Keeping a macro from going beyond selection Office 2016
Word 2013 Expert Cert
Keeping a macro from going beyond selection
 
Join Date: Sep 2009
Location: Virginia
Posts: 872
Ulodesk is on a distinguished road
Default Keeping a macro from going beyond selection

A session with the boss today stipulated certain optional space-saving formatting, which I am trying to put into a macro. The attached sample doc illustrates an original format and intended result.



Here's my recorded macro, which applies itself to the end of the document rather than stopping with the selection, highlighted here for clarity.

The lack of close parenthesis after the date format is simply something I don't know how to specify.

Code:
Sub BulletsToPara()
'
' BulletsToPara Macro
'
'
    Selection.Style = ActiveDocument.Styles("N-BodyText,n-bd")
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^t"
        .Replacement.Text = " ("
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^13"
        .Replacement.Text = ". "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "(..)"
        .Replacement.Text = "."
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ". . "
        .Replacement.Text = ". "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ".."
        .Replacement.Text = "."
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Attached Files
File Type: docx Sample.docx (14.7 KB, 7 views)
Reply With Quote
  #2  
Old 02-23-2022, 03:12 PM
Guessed's Avatar
Guessed Guessed is offline Keeping a macro from going beyond selection Windows 10 Keeping a macro from going beyond selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,161
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

Try this version
Code:
Sub BulletsToPara()
  Selection.Style = ActiveDocument.Styles("N-BodyText,n-bd")
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^t(*)^13"
    .Replacement.Text = " (\1)^13"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll

    .Text = "^13"
    .Replacement.Text = ". "
    .MatchWildcards = False
    .Execute Replace:=wdReplaceAll
    
    .Text = "(..)"    'not seeing the use of this one???
    .Replacement.Text = "."
    .Execute Replace:=wdReplaceAll
    
    .Text = ". . "
    .Replacement.Text = ". "
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-24-2022, 06:22 AM
Ulodesk Ulodesk is offline Keeping a macro from going beyond selection Windows 10 Keeping a macro from going beyond selection Office 2016
Word 2013 Expert Cert
Keeping a macro from going beyond selection
 
Join Date: Sep 2009
Location: Virginia
Posts: 872
Ulodesk is on a distinguished road
Default

Thank you very much , Andrew. I'm trying to learn from each one, and I think I understand a ew things better, since, for example, yours does not produced the several "do you want to continue" dialogues that mine does.

You left a note asking about the relevancy of replacing double periods with a single. For some reason, your macro leaves a double period anyway -- just one, right after "requirement". It's because, unlike the others, there is a period in the original, as would be the case if this were a completed resume and the paragraph between the Position, Employer line and first bullet were one or more complete sentences.

Would adding {1,} to the text-to-be-replaced period solve this, or maybe it's a matter of the order in which the actions are carried out?

Please forgive me for requesting one additional action, if I may. I have spent a half-hour trying to figure out how to add a removal of italics from any text in the selection to the macro, since I had forgotten that this is sometimes also needed (I did not include any in my sample). I tried recording, using a find-replace action, but once in the macro, either it returned some coding error message or simply did not remove the italics.

Last edited by Ulodesk; 02-24-2022 at 07:39 AM. Reason: Addition
Reply With Quote
  #4  
Old 02-24-2022, 02:55 PM
Guessed's Avatar
Guessed Guessed is offline Keeping a macro from going beyond selection Windows 10 Keeping a macro from going beyond selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,161
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

My question was about looking for (..) which was double periods inside brackets. I didn't see why that one was necessary. If you have double periods not inside brackets then you can add that case at the bottom.

You can remove italics right up the top by adding this line below the one included
Code:
Selection.Style = ActiveDocument.Styles("N-BodyText,n-bd")
Selection.Font.Italic = False
Alternatively, you can remove all local font attributes (bold, italic, colour, size etc) which might be overriding the style's font settings by using this line instead
Code:
Selection.Font.Reset
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 02-24-2022, 05:01 PM
Ulodesk Ulodesk is offline Keeping a macro from going beyond selection Windows 10 Keeping a macro from going beyond selection Office 2016
Word 2013 Expert Cert
Keeping a macro from going beyond selection
 
Join Date: Sep 2009
Location: Virginia
Posts: 872
Ulodesk is on a distinguished road
Default

Bravo again, Andrew. It's perfect now. Mille gracie. (That is Australian, isn't it?)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to auto add upon selection paulie102003 Excel Programming 2 01-04-2018 01:10 AM
Keeping a macro from going beyond selection How to trigger a macro on cell *selection* Larry_1 Excel Programming 6 12-24-2017 11:09 AM
Keeping a macro from going beyond selection Mail Merge keeping VBA Macro Piney Word VBA 5 08-03-2015 04:12 PM
Keeping a macro from going beyond selection Limiting a macro to a selection Ulodesk Word VBA 4 06-19-2012 06:09 AM
Printing a Selection in Word and keeping it in the same place on the page punkrae Word 0 03-29-2012 10:49 AM

Other Forums: Access Forums

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