Group: microsoft.public.word.vba.general
From: "Graham Mayor"
Date: Sunday, March 16, 2008 2:35 AM
Subject: Re: How I can re-apply all styles to a document programmatically?

The method suggested should work, however to doubly enforce the point add
the line

.ParagraphFormat.Reset
immmediately after
.Font.Reset

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


aushknotes wrote:
> Many thanks for your suggestion. However I have been using the same
> method as suggested. I also tried the organizercopy function to copy
> individual style across.
>
> The problem I am having is that once I copy the styles from the
> attached template, some paragraph styles have changed unwantedly. For
> example, I have some paragrahs formatted with "Heading x" without
> hanging indent, but once I update styles from template, some remains
> without indented (which is what I'm expecting), but some paragraghs
> (only some) changed to indented (which is not I'm expecting). I
> checked the style definitions in the template & they all look fine to
> me.
>
> This is why I am posting the question to see if there is any VBA
> method that can re-apply all the styles in the document AFTER I copy
> or update the styles from the attached template.
>
> Hope the additional information clarifies what exactly what I'm after.
>
> Have a nice weekend, guys!
>
>
>
>
>
> "Graham Mayor" wrote:
>
>> With ActiveDocument
>> .UpdateStylesOnOpen = True
>> .AttachedTemplate = "D:\Path\Template.dot"
>> End With
>>
>> The above will load your template and update the styles of the same
>> name. If you want to go beyond that and remove manual formatting,
>> then the following should do that and adds the facility to pick the
>> template.
>>
>> Neither function will do anything about stylenames that don't match.
>>
>> Sub ChangeMyTemplate()
>> Dim oRng As Range
>> Dim fDialog As FileDialog
>> Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
>> With fDialog
>> .Title = "Select Template to Attach and click OK"
>> .AllowMultiSelect = False
>> .InitialView = msoFileDialogViewList
>> If .Show <> -1 Then
>> MsgBox "Cancelled By User", , "Select Template"
>> Exit Sub
>> End If
>> sTemplate = fDialog.SelectedItems.Item(1)
>> End With
>> With ActiveDocument
>> .UpdateStylesOnOpen = True
>> .AttachedTemplate = sTemplate
>> End With
>> For Each oRng In ActiveDocument.StoryRanges
>> Do Until oRng Is Nothing
>> With oRng
>> .WholeStory
>> .Font.Reset
>> End With
>> Set oRng = oRng.NextStoryRange
>> Loop
>> Next
>> End Sub
>>
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> aushknotes wrote:
>>> Hi,
>>>
>>> I need to re-apply all styles to a document programmatically after
>>> copying all styles from a template? Is there a single method to do
>>> so? If not, how can I do it with the shortest VBA codes? I tried
>>> range.select & then send sendkeys CTRL+Q or CTRL+Space but both did
>>> not work as required.
>>>
>>> Many thanks in advance!


Safety Articles | Usenet Groups | Usenet News | Bluegrass