Home |
Search |
Today's Posts |
#1
|
|||
|
|||
VBA to Copy Template styles to many documents...is this OK?
Hi:
I have a collection of documents (*.doc files) in a directory, and I need them to all have the same style definitions. Unfortunately, my template changes over time, and I needed a macro (VBA code) to copy the styles from my updated template to all the documents. I did this in MS Word 2000, running in the MS Windows XP (Professional) environment. How does this look? It seems to work OK, except that it flashes the open document on the screen briefly (but I can live with that). -------------- start of the macro -------------------------------------- Sub CopyTemplate() ' ' CopyTemplate Macro ' Macro created 2005-01-16 by Barry Millman ' ' Gets all the .doc files in the directory (C:\temp)and applies the ' desired template to it (actually ' copies all the styles, and updates the ones with the same name). ' The template is: ' C:\Documents and Settings\Barry Millman\Application ' Data\Microsoft\Templates\CourseTemp1.dot ' With Application.FileSearch .FileName = "*.doc" .LookIn = "C:\temp" .Execute For I = 1 To .FoundFiles.Count myFile$ = .FoundFiles(I) ' Documents.Open FileName:=myFile$ ' open the file ' ' now copy the styles from template ' Template:=" ....." all on one line ' Documents(myFile$).CopyStylesFromTemplate _ Template:="C:\Documents and Settings\Barry Millman\Application Data\Microsoft\Templates\CourseTemp1.dot" ' Documents(myFile$).Close SaveChanges:=wdSaveChanges ' close & save ' Next I End With End Sub ----------------- end of macro ----------------------------- Is this a relatively efficient (it does work!) and bugproof way to do this or am I missing something major? Thanks, Barry |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Can't copy Autotext to new template | Microsoft Word Help | |||
word xp crashes after macros are recorded | Microsoft Word Help | |||
NEED TO COPY A TEMPLATE TO SECOND PAGE IN THE SAME DOCUMENT | Microsoft Word Help | |||
Deleting template affects styles, specifically font size. | Microsoft Word Help | |||
Continuous breaks convert to next page breaks | Microsoft Word Help |