|
|
|
date: Fri, 11 Jul 2008 09:37:01 -0700,
group: microsoft.public.word.vba.beginners
back
Re: Styles Macro
This works ( ActiveDocument.Styles("MyNewOne").NameLocal = "Blah")
BUT, then how would I include Multiple stylechanges within that same string?
So if I have a doc that has to have 10 different names changes, I want to be
able to have them all completed in one shot?\
Thanks for the info!
"fumei via OfficeKB.com" wrote:
> "So for instance, I need Bold Header1 to be renamed Bold Header2"
>
> I am not following. When you say rename, do mean the name of the style? Or,
> are you trying to change the style used, from one to another? As in:
>
> Find all instances of Body Text_ACSSC style , and change that text to Body
> Text_ACS style
>
> This is easy, but BOTH styles must exist.
>
> You can rename a style with something like:
>
> ActiveDocument.Styles("MyNewOne").NameLocal = "Blah"
>
> This would change "MyNewOne" to "Blah"
>
> Krumrei wrote:
> >I need the ability to take an exsisting Style within a Doc. and have a macro
> >to change the name of a specific style.
> >
> >So for instance, I need Bold Header1 to be renamed Bold Header2
> >
> >I have been looking at the replace feature in VB, but it does not seem to be
> >working. Here is the code I created to do that.
> >
> >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
> >
> > With Selection.Find
> > .ClearFormatting
> > .Replacement.ClearFormatting
> > .Style = ActiveDocument.Styles("Body Text_ACSSC")
> > .Text = ""
> > .Replacement.Style = ActiveDocument.Styles("Body Text_ACS")
> > .Execute Replace:=wdReplaceAll
>
> --
> Message posted via http://www.officekb.com
>
>
date: Fri, 11 Jul 2008 10:35:01 -0700
author: Krumrei
Re: Styles Macro
Thanks for the references.
One last question:
I have created this code, over and over repeating it for each Stlye in Word
to have the name replaced. I have over 20 lines of code, one for each Style
to be renamed.
However, how do I get it to continue the Macro, if the Name is not within
the style list?
If it is not in there, it just stops the Macro at the point of the unknown
or not listed Style within the document.
Basically, I want the program to skip and go to the next Sub, IF it has not
changed or recognized that the style listed in the document.
Paul
ActiveDocument.Styles("Body Text_ACSSC").NameLocal = "Body Text_ACS"
"Jean-Guy Marcil" wrote:
> "Krumrei" wrote:
>
> > Because we have to do this to over 5,000 documents and it would waste time on
> > our end, I think I may have figured it out. But still would like more idea's
> >
>
> See:
> http://word.mvps.org/faqs/macrosvba/BatchFR.htm
>
> and instead of replacing text, replace the styles.
>
> You may need to combine the batch code with the information here:
> http://word.mvps.org/faqs/macrosvba/FindReplaceAllWithVBA.htm
date: Fri, 18 Jul 2008 08:32:00 -0700
author: Krumrei
Re: Styles Macro
"Krumrei" wrote:
> Thanks for the references.
>
> One last question:
>
> I have created this code, over and over repeating it for each Stlye in Word
> to have the name replaced. I have over 20 lines of code, one for each Style
> to be renamed.
>
> However, how do I get it to continue the Macro, if the Name is not within
> the style list?
> If it is not in there, it just stops the Macro at the point of the unknown
> or not listed Style within the document.
>
> Basically, I want the program to skip and go to the next Sub, IF it has not
> changed or recognized that the style listed in the document.
>
First, check which of the target custom styles exist, then use that to do
the work.
Dim i As Long
Dim styCheck As Style
Dim strStyles As String
Dim varStyles As Variant
For i = 1 To ActiveDocument.Styles.Count
Set styCheck = ActiveDocument.Styles(i)
Select Case styCheck.NameLocal
Case "Body Text_ACSSC", "Body Text_AC", _
"Title_ACSSC", "Title_AC"
If strStyles = "" Then
strStyles = styCheck.NameLocal
Else
strStyles = strStyles & "|" & styCheck.NameLocal
End If
End Select
Next
If strStyles <> "" Then
varStyles = Split(strStyles, "|")
For i = LBound(varStyles) To UBound(varStyles)
'Do something to each of these styles...
Next
Else
MsgBox "None of the target custom styles were found in this document."
End If
date: Fri, 18 Jul 2008 09:57:01 -0700
author: Jean-Guy Marcil
|
|