Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2013, 08:46 AM
gundas gundas is offline Macro to change style name with " in it Windows 7 64bit Macro to change style name with " in it Office 2007
Novice
Macro to change style name with " in it
 
Join Date: Apr 2013
Posts: 3
gundas is on a distinguished road
Default Macro to change style name with " in it

I have tried the macro recorder but all it comes up with is the following

Sub Macro6()
'
' Macro6 Macro
'
'
Selection.Style = ActiveDocument.Styles("List 2")


Selection.Style = ActiveDocument.Styles("List 3")
End Sub

I have a style named Style Body + Left: 0.89" (I did not create this and was auto generated) but I need to replace that style with a style named List 3. I can not find the style in Find and Replace either under the formatting styles either. I can see List 3 but not Style Body + Left: 0.89". Please Help
Reply With Quote
  #2  
Old 04-01-2013, 04:35 PM
fumei fumei is offline Macro to change style name with " in it Windows 7 64bit Macro to change style name with " in it Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Styles with plus (+) show up in the Styles dropdown, but they are not "real" styles - they are not part of the searchable Styles collection. They are (sort of) temporary styles. Word puts them into the Styles dropdown (something I have always hated) when a manual format is made. A good reason to NEVER make manual formatting.

In other words, you can not use Find to find them.

That being said, you could search for a Body style, and THEN test to see if there is a left indent of 0.89.
Reply With Quote
  #3  
Old 04-01-2013, 06:31 PM
macropod's Avatar
macropod macropod is offline Macro to change style name with " in it Windows 7 64bit Macro to change style name with " in it Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,931
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

IIRC, the ' + Left: 0.89' doesn't denote part of the Style name, but a format that has been used to override it. Accordingly, you would have to Find paragraphs in the style named Style Body, then test their format to see whether they have the + Left: 0.89 formatting applied. The macro recorder won't do that. Try the following code:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Sty As Style, sOffset As Single
sOffset = CentimetersToPoints(0.89)
With ActiveDocument
  Set Sty = .Styles("Body Text")
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "^p"
      .Style = Sty.NameLocal
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute
    End With
    Do While .Find.Found
      With .Paragraphs(1)
        If CentimetersToPoints(Round(PointsToCentimeters(.LeftIndent), 2)) = _
          Sty.ParagraphFormat.LeftIndent + sOffset Then .Style = "List 3"
      End With
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
End With
Application.ScreenUpdating = True
End Sub
Note: the code assumes your 0.89 is Centimeters. If it's Inches, change 'Centimeters' in the code to 'Inches'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-02-2013, 06:20 AM
gundas gundas is offline Macro to change style name with " in it Windows 7 64bit Macro to change style name with " in it Office 2007
Novice
Macro to change style name with " in it
 
Join Date: Apr 2013
Posts: 3
gundas is on a distinguished road
Default

The code you provided worked like a charm. Thanks for the help.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to change style name with " in it How to globally change the formatting of a bullet style to another style? ravl13 Word 5 03-10-2013 05:04 PM
Macro to change style name with " in it "Table of content" based on "Normal Style" behavior!!!! Jamal NUMAN Word 4 07-08-2011 04:12 AM
Macro to change style name with " in it How the "Style" and the "List" are linked?? Jamal NUMAN Word 1 06-30-2011 05:18 PM
"Change Word Options" don't change ADKREV Word 0 11-12-2010 10:56 AM
How do I change the "and" to "or" with multiple Rules (and Alerts)? bschimmel Outlook 0 11-16-2009 05:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:30 PM.


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