Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2012, 09:23 PM
binar binar is offline Challenging Heading Edit with Find Replace Windows XP Challenging Heading Edit with Find Replace Office 2007
Advanced Beginner
Challenging Heading Edit with Find Replace
 
Join Date: Aug 2010
Posts: 41
binar is on a distinguished road
Default Challenging Heading Edit with Find Replace

Fellow Forum Members,

I got a Word File of a manual that has been formatted to follow some military standard.

Hence, my Headings need to look like this:

4.3.1 Blah Blah.

Setting up the "4.3.1" and the UNDERLINE is easy to do in the STYLES window. What is posing as a problem is the period (".") located at the end of the Heading. It needs to be at the end without UNDERLINE applied. The UNDERLINE only needs to be applied for the TITLE itself.

Can the FIND & REPLACE tool be used to add that "PERIOD" at the end of all the Headings in the entire 600 page manual? Below is another way of posing my question:

FIND = End of every Heading


REPLACE = Add a PERIOD but don't apply the UNDERLINE Style attribute.

Any ideas will be greatly welcomed because this one has really got me stumped. My goal is to avoid having to do this manually. Thanks in advance.
Reply With Quote
  #2  
Old 11-29-2012, 02:47 AM
macropod's Avatar
macropod macropod is offline Challenging Heading Edit with Find Replace Windows 7 64bit Challenging Heading Edit with Find Replace Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

You can use a Find/Replace that looks for periods at the end of a paragraph in the required Paragraph Style - or for paragraphs generally, where:
Find = .^p
Replace = ^&
with the 'Find' format specified as underlined and the 'Replace' format specified as not underlined.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-29-2012, 09:16 PM
binar binar is offline Challenging Heading Edit with Find Replace Windows XP Challenging Heading Edit with Find Replace Office 2007
Advanced Beginner
Challenging Heading Edit with Find Replace
 
Join Date: Aug 2010
Posts: 41
binar is on a distinguished road
Default

Macropod,
Thanks for your post. I'll try explaining it a different way because I'm not getting the results I need.

My objective is to insert a single period "." at the end of every underlined Heading and not have the underline attribute applied to the Period itself located at the end. I don't need it to search for Periods like you mention in your post.

I discovered today that I could select any Heading style inside the Styles dialog window. So I'm able to select all Heading Level 2 titles. Once selected I open the Find Replace tool and here is where I get stuck. How do I tell WORD to insert a period at the end of every Heading ? Any help will be greatly appreciated.
Reply With Quote
  #4  
Old 11-29-2012, 09:22 PM
macropod's Avatar
macropod macropod is offline Challenging Heading Edit with Find Replace Windows 7 64bit Challenging Heading Edit with Find Replace Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

The Find/Replace expressions in my previous post were for changing exiting periods to not underlined. To add periods to Heading 2 paragraphs that don't already have them, use a wildcard Find/Replace, where:
Find = ([!.])(^13)
Replace = \1.\2
and specify the Heading 2 Style. After that, do the standard Find/Replace from my previous post, retaining the Heading 2 Style and specifying the replacement as not underlined.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-05-2012, 08:44 PM
binar binar is offline Challenging Heading Edit with Find Replace Windows XP Challenging Heading Edit with Find Replace Office 2007
Advanced Beginner
Challenging Heading Edit with Find Replace
 
Join Date: Aug 2010
Posts: 41
binar is on a distinguished road
Default Followup

Thanks for your last post Macropod. I have been busy testing it and now I'm hoping you can advise me how to modify your code below:

Find = ([!.])(^13)
Replace = \1.\2

Let me say that your code makes quick work of adding a period at the end with no underline applied as long as I specify HEADING 2. Below is an example of the successful result I got for Heading 2:

3.2 Para Title With Heading 2 Specified.

However, if I specify HEADING 3, 4, 5 or Heading 6, I get incorrect results. Below is an example of the incorrect result I get when I specify HEADING 5 style:

3.6.5.5.5 Para Title With Heading 5 Specified.

It is incorrect because the "d" located at the end is missing the underline. Below is the correct result the Military Standard specifies for Heading 5:

3.6.5.5.5 Para Title With Heading 5 Specified.

My hope is you can advise me how to modify your code below:

Find = ([!.])(^13)
Replace = \1.\2

So that what it successfully does for Heading2 it can also do the same for HEADING 3, 4, 5 or Heading 6.

Any help will be greatly appreciated. Thanks
Reply With Quote
  #6  
Old 12-05-2012, 10:41 PM
macropod's Avatar
macropod macropod is offline Challenging Heading Edit with Find Replace Windows 7 64bit Challenging Heading Edit with Find Replace Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Hi Binar,

Appropos our previous discussion, you need to do a two-step Find/Replace. First, ensure all of the existing headings you want to modify have a period at the end, via the wildcard Find/Replace, where:
Find = ([!.])(^13)
Replace = \1.\2
and specify the relevant Heading Style for the 'Find'. Make sure the 'Replace' option doesn't have any format specified. After that, do another wildcard Find/Replace, where:
Find = .^13
Replace = ^&
again with the 'Find' format specified as the relevant Heading Style, but this time with the 'Replace' format specified as not underlined. This wildcard Find/Replace is equivalent to the standard one I specified originally - it just means you don't have to keep toggling the wildcard option on/off.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 12-09-2012, 09:17 PM
binar binar is offline Challenging Heading Edit with Find Replace Windows XP Challenging Heading Edit with Find Replace Office 2007
Advanced Beginner
Challenging Heading Edit with Find Replace
 
Join Date: Aug 2010
Posts: 41
binar is on a distinguished road
Default Followup

Quote:
Originally Posted by macropod View Post
Hi Binar,

Appropos our previous discussion, you need to do a two-step Find/Replace. First, ensure all of the existing headings you want to modify have a period at the end, via the wildcard Find/Replace, where:
Find = ([!.])(^13)
Replace = \1.\2
and specify the relevant Heading Style for the 'Find'. Make sure the 'Replace' option doesn't have any format specified. After that, do another wildcard Find/Replace, where:
Find = .^13
Replace = ^&
again with the 'Find' format specified as the relevant Heading Style, but this time with the 'Replace' format specified as not underlined. This wildcard Find/Replace is equivalent to the standard one I specified originally - it just means you don't have to keep toggling the wildcard option on/off.

Macropod,
Thank you for your last post. You mention two steps, however after much testing I think I'm missing a first step.

I am not he original author of this 600 page manual I'm working on. It looks like the previous author manually inserted PERIODS at the end of some HEADING styles. In other words, this manual I think first needs to be cleaned of all unaccounted PERIODS before I do the First and Second step you mention.

Can you please advise me how I could select HEADING Styles 1,2,4,5 and 6 all at the same time and then do a Find/Replace operation that deletes all of the unwanted periods located at the end of all HEADINGs? My goal is to first clean all of the HEADINGS of unaccounted PERIODS that were inserted by a previous author of this manual.

My theory is if I first clean all of the unaccounted PERIODS first and then apply the two steps you mention in your previous post I will get results that are error free. So instead of two steps to do I will be doing 3 steps:
  • Step #1. Clean entire manual of unaccounted periods at the end of Headings.
  • Step #2. Run this operation: Find = ([!.])(^13) - Replace = \1.\2
  • Step #3. Run this operation: Find = .^13 - Replace = ^&
As I mentioned this manual is 600 pages and the worst part is that it contains 900 HEADINGS (Levels 1 thru 6 Heading Styles). All of them need to be underlined with a PERIOD located at the end with no underline applied to the PERIOD. Therefore, I am really motivated to make this work because doing this manually would take a very long time. Any help will be greatly appreciated. Thanks again.
Reply With Quote
  #8  
Old 12-10-2012, 02:06 AM
macropod's Avatar
macropod macropod is offline Challenging Heading Edit with Find Replace Windows 7 64bit Challenging Heading Edit with Find Replace Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

There really are only two steps, both of which you've been given. The issue seems to be that you really don't understand what those two steps are doing and, perhaps, aren't implementing them correctly. Your 1 & 2 are already encompassed by my 1 (your 2).

The following macro implements both steps for all headings in the document.
Code:
Sub FixHeadings()
Application.ScreenUpdating = False
Dim i As Integer
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Format = True
    For i = 1 To 9
      .Style = "Heading " & i
      .Text = "([!.])(^13)"
      .Replacement.Text = "\1.\2"
      .Execute Replace:=wdReplaceAll
      .Text = ".^13"
      .Replacement.Text = "^&"
      .Replacement.Font.Underline = False
      .Execute Replace:=wdReplaceAll
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 12-22-2012, 09:21 PM
binar binar is offline Challenging Heading Edit with Find Replace Windows XP Challenging Heading Edit with Find Replace Office 2007
Advanced Beginner
Challenging Heading Edit with Find Replace
 
Join Date: Aug 2010
Posts: 41
binar is on a distinguished road
Default Followup

Macropod,
Thanks a million for your macro that you posted in your last post. Yesterday, I got to a stage in the manual where I had to address all of the (not underlined) PERIODS located at the end of all the (underlined) HEADING (Levels 1 through 6). In short, I ran your macro in my file and got the following results:

Your macro ran through 600 pages in very little time without a hiccup. It was successful in adding ending PERIODS to all HEADINGs (Levels 1 thru 6) with no UNDERLINE applied.

However, something in the code is making it subtract an additional single UNDERLINE space that is not needed. In other words, the macro does a great job of not applying an UNDERLINE to the PERIOD character located at the end, but then it goes a step beyond and also subtracts an additional UNDERLINE space from the last letter character located to the left of the PERIOD. In short, it looks like the example below:

3.4 Heading 2 Example.

What is incorrect is the "e" located to the left of the PERIOD character has no UNDERLINE applied. However, the "e" before running the Macro did have an UNDERLINE applied that was appled via the Heading 2 style setup.

In short, to comply to the Military Standard I had to go back and manually select each letter character located to the LEFT of the PERIOD and then apply the missing UNDERLINE by pressing CNTRL+U on the keyboard. THe document has HEADINGs paragraphs that number in the hundreds, so this took a long time. But the bright side is that I did not have to concern myself with adding PERIOD characters at the end with no UNDERLINE applied because your macro took care of that.

So in retrospect your macro was helpful, but it would be perfect if it could be prevented from also removing the additional UNDERLINE space located to the left of the PERIOD character.

Nevertheless, thanks for your help Macropod. I enjoy what I am learning from this thread. Have a great XMAS and a happy New Year!

Last edited by macropod; 12-22-2012 at 10:52 PM. Reason: Deleted unnecessary quote of entire post replied to
Reply With Quote
  #10  
Old 12-22-2012, 11:07 PM
macropod's Avatar
macropod macropod is offline Challenging Heading Edit with Find Replace Windows 7 64bit Challenging Heading Edit with Find Replace Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Hi binar,

Quote:
something in the code is making it subtract an additional single UNDERLINE space that is not needed. In other words, the macro does a great job of not applying an UNDERLINE to the PERIOD character located at the end, but then it goes a step beyond and also subtracts an additional UNDERLINE space from the last letter character located to the left of the PERIOD. In short, it looks like the example below:

3.4 Heading 2 Example.
That suggests your heading Styles don't include the underlining and someone has applied that manually. That is a poor use of the Styles. Used correctly - with the underlining applied to the Style definitions, this would not occur. Ideally, you should get the Style deinitions right before running the macro.

Nevertheless, even without getting the Style definitions right you can work around the issue by inserting:
.Replacement.Font.Underline = True
before the first:
.Execute Replace:=wdReplaceAll

And, if you've already saved your work with the 'erroneous' underlining, you can redeem it by changing the first F/R expression to:
.Text = "([!.].)(^13)"
.Replacement.Text = "\1\2"
(with the addition of the '.Replacement.Font.Underline = True' line).

PS: Please don't automatically quote the entire post replied to each time you post. It's quite unnecessary and just clutters the thread. If there's a particular element of the post replied to that warrants quoting, then quote just that portion - as I have done in this reply.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 12-23-2012, 08:16 PM
binar binar is offline Challenging Heading Edit with Find Replace Windows XP Challenging Heading Edit with Find Replace Office 2007
Advanced Beginner
Challenging Heading Edit with Find Replace
 
Join Date: Aug 2010
Posts: 41
binar is on a distinguished road
Default Followup

Macropod,
Thanks a million for your last post. I can assure you with 100% certainty that all of the UNDERLINE formatting for all HEADING (Levels 1 thru 6) were applied by activating the UNDERLINE button within the Style Definition for each HEADING style. I can assure you of this because I was the one that did it.

The original author was not following Military Standard 38784. However, when I took over the document I was tasked with changing it over to MIL STD 38784 and one of the first things I did was apply all of the UNDERLINE formatting because I immediately realized this change could easily be done by making a small change to the Style Definition for each HEADING style. However, when it got to adding all of the PERIODs I remember not being a happy camper because this document has way too many heading paragraphs to manually add PERIODs to one by one. In addition, I noticed that some HEADINGs already had PERIODs applied while others did not. This is when I decided to start this thread in an effort to learn how the mundane task of adding PERIODs (with no underline applied) could be done with very little effort.

When I get back to work after the New Year holiday I will try out the code below on a backup copy I made of the document before applying your macro and let you know if adding the extra line of code fixes the problem with additional underline subtraction. Again, thanks a million for your help with this code. Your contribution to this thread is very much appreciated.


Code:
 
 
Sub FixHeadings()
Application.ScreenUpdating = False
Dim i As Integer
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Format = True
    For i = 1 To 9
      .Style = "Heading " & i
      .Text = "([!.])(^13)"
      .Replacement.Text = "\1.\2"
   .Replacement.Font.Underline = True
      .Execute Replace:=wdReplaceAll
      .Text = ".^13"
      .Replacement.Text = "^&"
      .Replacement.Font.Underline = False
      .Execute Replace:=wdReplaceAll
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Challenging Heading Edit with Find Replace Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM
Challenging Heading Edit with Find Replace Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Challenging Heading Edit with Find Replace Is there a way to use "find/replace" to find italics words? slayda Word 3 09-14-2011 02:16 PM
Challenging Heading Edit with Find Replace Find and Replace kjxavier Excel 3 08-12-2011 10:49 PM
Challenging Heading Edit with Find Replace Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:28 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft