Custom style inside the Word file with macro

xiaoxiao2021-03-06  14

'Use the following macro, you can copy all custom style of the D: /DB/A.Doc document to the current document

'How to close the open d: /db/a.doc, now I don't know how to make an error, then look at it later.

Sub copymyStyles () 'Copy Custom Style Macro' Macro in 2005-03-10 Created by Hu Dan '

'To apply the document (current document) DIM STRDEST AS STRINGSTRDEST = ActiveDocument.FullName

'Template Document Location DIM STRTEMPLETE AS STRINGSTEMPLETE = "D: /DB/A.DOC"

DIM WRD AS ApplicationSet WRD = GetObject (, "Word.Application") WRD.Documents.Open (Strtemplete) WRD.Visible = TRUE

Dim Styleloop As Style On Error Goto Theerror

For Each styleLoop In wrd.ActiveDocument.Styles If styleLoop.BuiltIn = False Then Application.OrganizerCopy Source: = strTemplete, _ Destination: = strDest, _ Name: = styleLoop.NameLocal, _ Object: = wdOrganizerObjectStyles End IfNext styleLoop

Msgbox "Import Success" Goto Thelast

Theerror: MsgBox "error"

Thelast: 'DIM D As Document'for Each D in Wrd.Documents' IF D.Fullname = Strtemplete Ten 'D.close (WDDONOTSAVECHANGES)' End If'Next D'set WRD = Nothingend Sub

转载请注明原文地址:https://www.9cbs.com/read-48747.html

New Post(0)