Ms word 将特定样式指定给多个word文件而不打开它们

Ms word 将特定样式指定给多个word文件而不打开它们,ms-word,ms-office,Ms Word,Ms Office,我通过创建样式在wordthrough中创建了一个新样式。。。我想把这个样式分配给200字的文件。逐个打开它们并为其指定样式非常耗时。有没有办法在不打开它们的情况下为它们指定样式?最简单的方法是使用Word VBA 将要指定样式的200字文件放置到不包含其他文件的目录中。然后在其他位置创建.dotm Word 2007或更高版本或.dot Word 2003或更低版本的模板文件。创建要在模板文件中复制的样式,并将以下代码放入同一模板文件ALT-F11中的模块中,以访问编辑器: Sub Batch

我通过创建样式在wordthrough中创建了一个新样式。。。我想把这个样式分配给200字的文件。逐个打开它们并为其指定样式非常耗时。有没有办法在不打开它们的情况下为它们指定样式?

最简单的方法是使用Word VBA

将要指定样式的200字文件放置到不包含其他文件的目录中。然后在其他位置创建.dotm Word 2007或更高版本或.dot Word 2003或更低版本的模板文件。创建要在模板文件中复制的样式,并将以下代码放入同一模板文件ALT-F11中的模块中,以访问编辑器:

Sub BatchCopyStyles()

'Make sure that the template that contains the style to be copied and this code 
'is open and acting as the active document before running this macro

Dim file As Variant
Dim folderPath As String 'path to files receiving the style
Dim targetPath As String 
Dim templateFile As String 'file that contains style and this code
Dim styleTemplate As Document

folderPath = "C:\Users\Joe\Desktop\TargetFolder\"
templateFile = "C:\Users\Joe\Desktop\CopyStyle.dotm"

Set styleTemplate = ActiveDocument
file = Dir(folderPath)

    While (file <> "")
        Set file = Documents.Open(FileName:=folderPath & file)
        styleTemplate.Activate
        targetPath = folderPath & file
        Application.OrganizerCopy Source:=templateFile, _
                    Destination:=targetPath, _
                    Name:="StyleToCopy", _
                    Object:=wdOrganizerObjectStyles
        file.Close wdSaveChanges
        file = Dir
    Wend
End Sub
编辑正确路径、文件名、样式名等的代码。使用包含此代码的文件和要指定为活动文档的样式,从VBA编辑器F5运行宏。这将打开每个文件,复制样式,然后关闭文件。打开和关闭一个文档200次并不漂亮,但它应该可以完成这项工作