Copying Styles from a Global template to normal.dot

M

Missy Mason

Hi,

Any help with this would be greatly appreciated. I am trying to access
styles from a global template. I have the global template located in the
Startup directory, and it loads okay, but I don't have access to any of
styles. I thought I would copy the styles from the global template to
normal.dot I want to do it all through code as I am working with low-end
Word users. I have developed the code outlined below, but it crashes
whenever I try to run it. I first tried various strategies, but each time,
it dies when trying to copy the style. Any help would be greatly
appreciated.

Any suggestions?

Code:

Application.DOCUMENTS.Open FileName:="C:\Documents and Settings\. .
..\Application Data\Microsoft\Word\STARTUP\My Custom.dot"

For Each sty In ActiveDocument.Styles
If sty.BuiltIn = False Then
Application.OrganizerCopy Source:= _
"C:\Documents and Settings\. . .\Application
Data\Microsoft\Word\STARTUP\My Custom.dot" _
, Destination:= _
"C:\Documents and Settings\. . .\Application
Data\Microsoft\Templates\Normal.dot" _
, Name:=sty.NameLocal, Object:=wdOrganizerObjectStyles
End If
next sty

End Sub
 
C

Charles Kenyon

Don't mess with your user's normal.dot unless there is no other way to reach
your goal. The proper way to be using styles is in document templates, not
global templates. Set up document templates that give your users the styles
you want them to have. If you want, you can use an AutoNew macro to copy
selected styles from any source including a document, a closed template, or
a global template.

So, your macro should be copying into your active document, not into
normal.dot. I'm curious as to why you are excluding built-in styles from
your copying. Also, you should repeat the copies three times and make sure
you are copying not only the styles your are using but any that they are
based upon.

The following code copies specified styles from a global template to the
active document. The template is the same file as contains the code.

Sub PleadingStyleTransfer()
'
' PleadingStyleTransfer Macro
' Macro written 14 November 2001 by Charles Kyle Kenyon
'
On Error GoTo NoDocument 'In case called when no document is open.
Dim sThisTemplate As String
Dim sTargetDoc As String
Dim i As Integer
Dim iCount As Integer
Dim rResponse As Variant 'vbMsgBoxResult in Word 2000 or later
sThisTemplate = ThisDocument.FullName
sTargetDoc = ActiveDocument.FullName 'generates error if no document
open
rResponse = MsgBox(Prompt:="This command redefines your Body Text Style
and" _
& vbCrLf & "Heading Styles 1-9. Are you sure you want to do this?" _
& vbCrLf & vbCrLf & "If you are not sure, answer 'No' and make a
backup of your document." _
& vbCrLf & "Then run the command to copy the styles again.", _
Title:="Are you sure you want to redefine your styles?", _
Buttons:=vbYesNo + vbExclamation)
If rResponse = vbNo Then Exit Sub
On Error Resume Next
' Copy Body Text and Pleading Styles to Active Document
For i = 1 To 3 ' copy styles three times
StatusBar = "Copying Styles - Round " & i & " of 3"
With Application
.OrganizerCopy Source:=sThisTemplate, _
Destination:=sTargetDoc, Name:="Body Text,bt,bt1", Object:=
_
wdOrganizerObjectStyles
StatusBar = i & "/3: Body Text"
For iCount = 1 To 9
.OrganizerCopy Source:=sThisTemplate, _
Destination:=sTargetDoc, Name:= _
"Heading " & iCount & ",h" & iCount & ",Pleading " &
iCount _
& ",p" & iCount, Object:= _
wdOrganizerObjectStyles
StatusBar = i & "/3: Pleading " & iCount & " copied"
Next iCount
End With
Next i
StatusBar = "All styles copied."
' Change to Pleading 1 style?
rResponse = MsgBox(Prompt:="Change to Pleading 1 style and go into
Outline view?", _
Buttons:=vbYesNo, Title:="Pleading Styles Imported - start
writing?")
If rResponse = vbYes Then
Selection.Style = ActiveDocument.Styles("Heading 1,h1,Pleading
1,p1")
ActiveWindow.ActivePane.View.Type = wdMasterView
Else 'not now - then reminder
MsgBox Prompt:="The style to start your pleading is Pleading 1 or
p1." _
& vbCrLf & "It is probably easiest to work in Outline view."
End If
Exit Sub
NoDocument:
MsgBox Prompt:="Sorry, this command is only available when you have a
document open." _
& vbCrLf & "It should be used after you have your caption set up.", _
Title:="No document open!", Buttons:=vbExclamation
End Sub

My code contains user messages and other things you may not need and is for
specific styles. Try modifying it.

Those templates that will use these styles are set up with them already in
the template. An autonew macro in the template uses
Application.Run macroname:=PleadingStyleTransfer

This means that the styles can be changed in that single template and will
influence styles in new documents from any template containing that line in
the autonew macro. You could add a procedure updating the styles in your
document template at the same time, if you want.
--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

Word Resources Page
<URL: http://www.addbalance.com/word/wordwebresources.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

Word Resources Page
<URL: http://www.addbalance.com/word/wordwebresources.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
M

Missy Mason

Hi,

Thank you so much for your help. I will try that out. I am not copying any
of the built-in styles because I have not modified any of those styles.

Thanks again.

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top