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

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!