S
Susan J-P
Greetings:
To begin with, I'm *not* a programmer, so please keep this in mind when you
reply. This is a relatively long post on the theory that too much information
and detail up front is better than too little.
I'm using Word 2003 on Windows XP.
Problem I'm trying to resolve: automatically unselect the "Automatically
update document styles" on the Tools/Templates and Add-Ins... dialog whenever
someone uses the dialog to refresh a document's styles from its attached
template. I've been following the steps detailed in the MVP article at
http://word.mvps.org/faqs/macrosvba/UpdateStyles.htm with partial success but
am encountering some frustrating issues.
The code below (snipped from the article) breaks the document's attachment
to a custom global template (after I refresh the document styles), and with
the Tools/Templates and Add-Ins... dialog mostly greyed out, I can't reattach
it without quitting Word and restarting:
Sub FileTemplates()
With Dialogs(wdDialogToolsTemplates)
.Show
If .LinkStyles = 1 Then
ActiveDocument.UpdateStyles
Dim oLT As ListTemplate
On Error Resume Next
For Each oLT In ActiveDocument.AttachedTemplate.ListTemplates
If Not oLT.Name = "" Then
If Not ActiveDocument.ListTemplates(oLT.Name).ListLevels(1) _
.LinkedStyle = oLT.ListLevels(1).LinkedStyle Then
ActiveDocument.UpdateStyles
Exit For
End If
End If
Next oLT
ActiveDocument.UpdateStylesOnOpen = False
End If
End With
End Sub
When I try the code below (also snipped from the MVP article -- a workaround
to the menu display bug from the first solution), it errors out at the first
line:
CommandBars.FindControl(ID:=751).Execute
and I haven't been able to figure out why.
Sub ReplacementToolsTemplatesAndAddins()
'Execute the built-in button
CommandBars.FindControl(ID:=751).Execute
If Dialogs(wdDialogToolsTemplates).LinkStyles = 1 Then
Dim oDoc As Document, oLT As ListTemplate
Set oDoc = ActiveDocument
oDoc.UpdateStyles
On Error Resume Next
For Each oLT In oDoc.AttachedTemplate.ListTemplates
If Not oLT.Name = "" Then
If Not oDoc.ListTemplates(oLT.Name).ListLevels(1) _
.LinkedStyle = oLT.ListLevels(1).LinkedStyle Then
oDoc.UpdateStyles
Exit For
End If
End If
Next oLT
oDoc.UpdateStylesOnOpen = False
End If
End Sub
All I really need here is to have a failsafe for the "Automatically update
document styles" checkbox, and to keep (or reattach) my custom global
template.
Thanks in advance for your help,
To begin with, I'm *not* a programmer, so please keep this in mind when you
reply. This is a relatively long post on the theory that too much information
and detail up front is better than too little.
I'm using Word 2003 on Windows XP.
Problem I'm trying to resolve: automatically unselect the "Automatically
update document styles" on the Tools/Templates and Add-Ins... dialog whenever
someone uses the dialog to refresh a document's styles from its attached
template. I've been following the steps detailed in the MVP article at
http://word.mvps.org/faqs/macrosvba/UpdateStyles.htm with partial success but
am encountering some frustrating issues.
The code below (snipped from the article) breaks the document's attachment
to a custom global template (after I refresh the document styles), and with
the Tools/Templates and Add-Ins... dialog mostly greyed out, I can't reattach
it without quitting Word and restarting:
Sub FileTemplates()
With Dialogs(wdDialogToolsTemplates)
.Show
If .LinkStyles = 1 Then
ActiveDocument.UpdateStyles
Dim oLT As ListTemplate
On Error Resume Next
For Each oLT In ActiveDocument.AttachedTemplate.ListTemplates
If Not oLT.Name = "" Then
If Not ActiveDocument.ListTemplates(oLT.Name).ListLevels(1) _
.LinkedStyle = oLT.ListLevels(1).LinkedStyle Then
ActiveDocument.UpdateStyles
Exit For
End If
End If
Next oLT
ActiveDocument.UpdateStylesOnOpen = False
End If
End With
End Sub
When I try the code below (also snipped from the MVP article -- a workaround
to the menu display bug from the first solution), it errors out at the first
line:
CommandBars.FindControl(ID:=751).Execute
and I haven't been able to figure out why.
Sub ReplacementToolsTemplatesAndAddins()
'Execute the built-in button
CommandBars.FindControl(ID:=751).Execute
If Dialogs(wdDialogToolsTemplates).LinkStyles = 1 Then
Dim oDoc As Document, oLT As ListTemplate
Set oDoc = ActiveDocument
oDoc.UpdateStyles
On Error Resume Next
For Each oLT In oDoc.AttachedTemplate.ListTemplates
If Not oLT.Name = "" Then
If Not oDoc.ListTemplates(oLT.Name).ListLevels(1) _
.LinkedStyle = oLT.ListLevels(1).LinkedStyle Then
oDoc.UpdateStyles
Exit For
End If
End If
Next oLT
oDoc.UpdateStylesOnOpen = False
End If
End Sub
All I really need here is to have a failsafe for the "Automatically update
document styles" checkbox, and to keep (or reattach) my custom global
template.
Thanks in advance for your help,