Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-09-2017, 03:31 PM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default Normalising styles with +condensed

I've inherited a document (200+ pages) which I have to clean up.

The document has many styles of the form <style name> + condensed <number>


The following code doesn't normalise these styles and I can't seem to delete them manually. They go but then come back again.

I've turned off the sub-pixelling option for screen display. But now I'm stuck



Any help would be appreciated.

Code:
Sub NoCondensedandStuff()

Dim mystyle As Style
For Each mystyle In ActiveDocument.Styles
   Debug.Print "Processing " & mystyle.NameLocal
   With mystyle.Font
      .Spacing = 0
      .Scaling = 100
      .Position = 0
      .Kerning = 0
   End With
   ActiveDocument.UndoClear
Next
End Sub
Reply With Quote
  #2  
Old 02-09-2017, 04:10 PM
macropod's Avatar
macropod macropod is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed 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

Changing the Style definitions won't delete Styles named in the form <style name> + condensed <number>. You would have to delete those Styles. To do that, though, you'd probably want to reapply each <style name> without the 'condensed' part to all affected content in the document; otherwise deleting the Styles named <style name> + condensed <number> would see all their content revert to the Normal Style.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-09-2017, 04:21 PM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Reapply the basestyle is the clue I needed. I feel a macro coming on.

Many thanks again
Reply With Quote
  #4  
Old 02-09-2017, 05:27 PM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

This isn't as easy as I tought.

If I go to the style pane I will find lots of sequences like

<style name>
<style name> + condensed <number1>
<style name> + condensed <number2>
<style name> + condensed <number3>
<style name> + condensed <number4>
<style name> + condensed <number5>
<style name> + condensed <number6>

etc

If I select all instances of one of the lines above (from the style pane) it is individual characters that are affected. If I the use the font tab on the ribbon to reset the condensed setting back to normal, that particular style dissappears from the task pane. It seems I was deleting but as there are lits it didn't seem like they were diminishing. To write a macro I either have to be able to acces the style pane facility for selecting al instances of a style or search through the document on a character by character basis.

Its not clear why my code above doesn't work when emulating the same operation from the style pane does work.

Condensed is the example I'm using . I also have lots and lots of expanded, left, right, raised, lowered, in multifarious combinations so finding a macro solution would be great. All of this stuff is unecessary extraneous formatting which can be safely removed.


Any more thoughts.
Reply With Quote
  #5  
Old 02-10-2017, 05:00 PM
Boris_R Boris_R is offline Normalising styles with +condensed Windows Vista Normalising styles with +condensed Office 2010 32bit
Novice
 
Join Date: Oct 2015
Posts: 6
Boris_R is on a distinguished road
Default

Quote:
Originally Posted by slaycock View Post
I also have lots and lots of expanded, left, right, raised, lowered, in multifarious combinations so finding a macro solution would be great. All of this stuff is unecessary extraneous formatting which can be safely removed.
Any more thoughts.
Try it on the copy. Perhaps, will help
Code:
Sub reset_FP()
    With ActiveDocument.Range
        .Font.Reset
        .Paragraphs.Reset
    End With
End Sub
Reply With Quote
  #6  
Old 02-12-2017, 02:12 AM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Thanks for the suggestion. However because of a design decision some of the styles affected rely on user applied local formatting. e.g. we only have one style for tables which is 'Table text'. Users a directed by the style guide to use local formatting such a bold for heading text or to center /right align text within tables. Consequently your code can't be used as I wish to retain correct local formatting but get rid of unwanted formatting.

The unwanted formatting is easy to identify by a comparison against the base style.

BUT the only way I worked out to do this is on a character by character basis. This is because when you use the style pane you can select all instances of the particular style and when I do this I can see that in many cases there are only individual characters or words affected. Sometimes only 1 instance, sometimes many hundreds of instances.

I have a strong suspicion that some of the underlying problems are due to the fact that parts of the final document came from sections authored in Japan.

I'll keep scratching my head. But other suggestions are welcome.
Reply With Quote
  #7  
Old 02-12-2017, 02:47 AM
macropod's Avatar
macropod macropod is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed 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

Try:
Code:
Sub DeleteCondensedStyles()
Dim Doc As Document, i As Long, Rng As Range, StlNmFnd As String, StlNmRep As String
Application.ScreenUpdating = False
Set Doc = ActiveDocument
With Doc
  For i = .Styles.Count To 1 Step -1
    With .Styles(i)
      If .BuiltIn = False Then
        If .Type = wdStyleTypeCharacter Then
          StlNmFnd = .NameLocal
          If InStr(StlNmFnd, "+") > 0 Then
            StlNmRep = Trim(Split(StlNmFnd, "+")(0))
            For Each Rng In Doc.StoryRanges
              With Rng.Find
                .ClearFormatting
                .Format = True
                .Style = StlNmFnd
                .Replacement.Style = StlNmRep
                .Execute Replace:=wdReplaceAll
              End With
            Next
            If .Linked = True Then
              Doc.Styles.Add Name:="TmpSty"
              .LinkStyle = "TmpSty"
              Doc.Styles("TmpSty").Delete
            Else
              .Delete
            End If
          End If
        End If
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 02-12-2017, 03:41 AM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Macropod

Thanks for the suggestion. Unfortunately when iterating through the style collection the troublesome styles are not found. i.e. the following code prints nothing.

Code:
Sub findplus()

Dim myindex As Long
    For myindex = 1 To ActiveDocument.Styles.Count
        If InStr(ActiveDocument.Styles(myindex).NameLocal, "+") > 0 Then
            Debug.Print ActiveDocument.Styles(myindex).NameLocal
        End If
    Next
End Sub
The troublesome styles disappear from view (but not from the document) in the style task pane if the show paragaph level formatting check box is unchecked (Style Pane Options dialog box - options from the style task pane)
Reply With Quote
  #9  
Old 02-12-2017, 03:52 AM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Macropod, If it helps I can send an anonymized document for you to have a good laugh with.([a-zA-X replaced with x and inlineshsapes replaced by a text statement)
Reply With Quote
  #10  
Old 02-12-2017, 03:16 PM
macropod's Avatar
macropod macropod is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed 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

OK, if you attach said document to a post, I'll take a look at it. You can do that via the paperclip symbol on the 'Advanced' posting menu.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 02-12-2017, 03:42 PM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Macropod. Much appreciated. I'd really like to find a programmatic way of resolving this conundrum. The file is uploaded as a zip file as it is too large to upload as docx.

The file is anonymised by replacing all characters with x and replacing inlineshapes with a text statement.

Since creating the anonymised version I've resolved the issue with heading numbering by creating a new document from the template and importing the old document into the new document.

The 'design philosophy is that the user only sees a very short list of recommended styles (14 at the minimum) but depending on the task they are doing they can add in other sets of styles through a customised ribbon. That bit will be missing from the anonymised document.

Thanks again
Attached Files
File Type: zip AllAsX.zip (841.8 KB, 63 views)
Reply With Quote
  #12  
Old 02-12-2017, 05:29 PM
macropod's Avatar
macropod macropod is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed 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

Your document has far more going on than just 'condensed' Styles; in fact, it has about 250 custom Styles with micro-variations on the base styles. The simplest way of cleaning up this mess is to:
1. Create a new 'base' document containing just the Styles you want to use;
2. Save the existing document in RTF format
3. Open the document in WordPad, make an edit somewhere, then re-save & close.
4. Re-open the edited RTF document in Word and copy and paste its content into the new 'base' document as formatted text;
5. Re-apply the required Styles.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 02-13-2017, 12:53 AM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Macropd. Thanks for the advice. Horrible isn't it. It never ceases to amaze me what people get upto with word. The previous document I was working on had floating text boxes as headers (not in the heading) and diagrams where text had been laid out with newpaper columns and then floating text boxes drawn around the tabbed text!!!!
Reply With Quote
  #14  
Old 02-13-2017, 01:09 AM
macropod's Avatar
macropod macropod is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed 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

That suggests the previous version might have at some stage been in PDF or print format and a low-end OCR package was used to convert it to a Word document. Such horrid outcomes are typical of low-end OCR packages.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 02-14-2017, 11:14 AM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Quote:
Your document has far more going on than just 'condensed' Styles; in fact, it has about 250 custom Styles with micro-variations on the base styles. The simplest way of cleaning up this mess is to:
1. Create a new 'base' document containing just the Styles you want to use;
2. Save the existing document in RTF format
3. Open the document in WordPad, make an edit somewhere, then re-save & close.
4. Re-open the edited RTF document in Word and copy and paste its content into the new 'base' document as formatted text;
5. Re-apply the required Styles.
I considered the above but 5 made me baulk. Its exactly what I'm trying to avoid.

After some headscratching I came up with the following code

Code:
Sub ConsolidateStyleVariations()

Dim myStyle As Style
Dim myRange As Range
Dim myChar As Range
Dim myPage As Long

    Application.ScreenUpdating = False
    myPage = 0
    For Each myChar In ActiveDocument.StoryRanges(wdMainTextStory).Characters
         Set myStyle = myChar.Style
         If myPage + 5 < myChar.Information(wdActiveEndPageNumber) Then
            DoEvents
            myPage = myPage + 5
        End If
        If myChar.Fields.Count = 0 Then
             myChar.Font.Spacing = 0
             myChar.Font.Scaling = 100
             myChar.Font.Name = myStyle.Font.Name
             If Not myChar.Font.Position = 0 Then
                 If myChar.Font.Position > 0 Then
                     myChar.Font.Position = 0
                     myChar.Font.Superscript = True
                 End If
                 If myChar.Font.Position < 0 Then
                     myChar.Font.Position = 0
                     myChar.Font.Subscript = True
                 End If
             End If
             If myStyle.Type = wdStyleTypeParagraph Then
                 myChar.ParagraphFormat.FirstLineIndent = myStyle.ParagraphFormat.FirstLineIndent
                 myChar.ParagraphFormat.LeftIndent = myStyle.ParagraphFormat.LeftIndent
             End If
         End If
    Next
    Application.ScreenUpdating = True
End Sub
This works for me because

a. I dont have any styles in my document with changed spacing,position or scaling
b. There are very very few occasions where firstline and left indents differ from the style so I'm prepared to take the hit.

There were a couple of issues

• The fields statement doesn't capture drawing boxes. WHen I checked I only had 4 such items, 3 of which did not convert to inline shape. So when the macro fell over I just set it to continue at the next statement

• It takes a loong time to run, hence the inclusion of do events
• It took 13 hours to run before I added the screen updating commands

The code works because for dynamically created styles (which was creating the issue) if you reset those style to remove the items after the + then this allows word to obligingly remove the dynamic style.

Any comments on adding code to trap drawing boxes or make it more robust/faster would be most welcome.

For now I'm a lot happier as I have a document that is editable (I don't have to wait 5-10 seconds for the document to update every time I make an edit and it is a programmatic solution so can be added to the suite of 'Triage' macros I'm assembling.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Normalising styles with +condensed different hyperlink-styles in two superior styles -SLIME- Word 1 04-09-2016 08:51 AM
Normalising styles with +condensed Need some urgent condensed Project knowledge!! Halesowenmum Project 1 10-06-2014 06:18 PM
Normalising styles with +condensed Restricting paragraph styles without restricting character styles Red Pill Word 5 05-25-2012 01:06 PM
Can't Display "Recently Used Styles" in Styles Pane mwildem Word 2 05-23-2012 01:42 PM
Normalising styles with +condensed Quick Styles Set saved but it doesnt appear at the styles list! Pedro77 Word 3 10-15-2011 05:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:18 PM.


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