V_Error = "|" & V_Style & "| is no valid style name, neither in the document nor in the template!" If Err.Number = 0 Then 'no error, style found in templateĮlseIf Err.Number = 5608 Then 'is no style name V_Template = & Application.PathSeparator & Sub AddMissingStyleFromTemplate(V_Style, Optional V_Error) V_Errors = V_Errors & IIf(V_Error = "", "", V_Error & vbCr) If V_ErrNumber = 5941 Then Call AddMissingStyleFromTemplate(V_Style, V_Error) Else V_Error = "" Tmp = ActiveDocument.Styles(V_Style).Font.Size 'checking whether style exists Sub VerifyExistenceOfStyles(A_Styles, Optional V_Errors)
I don't know whether you are happy about the above solutions, but since the question is still listed as "unanswered", here the - somewhat simplified - code I am using for exactly this problem: Sub Test()Ĭall VerifyExistenceOfStyles(A_Styles, V_Errors) Style_exists = test_document.Styles(style_name).NameLocal = style_name ' style_exists = TRUE Style "style_name" exists in document If B_fail Then MsgBox "Copy of style " & style_name & " to " & _ĭestination_document.Name & " failed", vbCriticalįunction style_exists(test_document As Word.Document, style_name As String) As Boolean Name:=style_name, Object:=wdOrganizerObjectStylesī_fail = Not style_exists(destination_document, style_name) OrganizerCopy Source:=.NormalTemplate.FullName, _ĭestination:=destination_document.FullName, _ ' copy style "style_name" from Normal template to "Style """ & style_name & """ does not exist in Normal.dotm", vbCritical VbCr & destination_document.Name & " :" & vbCr & vbCr & _ MsgBox "Cannot copy style """ & style_name & """ from Normal.dotm to " & _ ' Style "style_name" not in Normal template, exit: Set normal_template = ī_Normal = style_exists(normal_template, style_name) ' open the Normal template as a document, and test if style "style_name" is If style_exists(destination_document, style_name) Then Exit Sub ' test if style "style_name" is already present in ' Adds the style "style_name" from the Normal template to the styles available Sub add_style_from_Normal(destination_document As Word.Document, _ I have tested the following code, and found it to work (Word 2013): Sub test_style_copy()Ĭall add_style_from_Normal(ActiveDocument, "Orcamento", B_failed)
The problem with the original code is that the Destination parameter in Application.OrganizerCopy needs to be a string - the full path of destination document. , Name:="tw4winInternal", Object:=wdOrganizerObjectStylesĪny help at all with this? I have about a hundred files that need formatted, so importing individually is kind of out of the question. , Name:="tw4winExternal", Object:=wdOrganizerObjectStyles , Name:="DO_NOT_TRANSLATE", Object:=wdOrganizerObjectStyles "C:\Users\Inu\AppData\Roaming\Microsoft\Templates\Normal.dotm", _ Here's what I have so far: Application.OrganizerCopy Source:= _ The easiest way would be to create a macro (or add to my current) that would automatically import these 3 styles from the global template to the active document. My Normal.dotm global template has the 3 font styles that the macro uses, however the macro stops because it repeatedly cannot find the style the macro calls upon. Styles elements from the current document will be overwritten by the copied style elements.I have a macro that runs across all files in a given folder. Word will prompt the message, “Do you wish to overwrite the existing style entry element?” Click Yes or Yes to All. Select the styles (Heading 1, Heading 2, Heading 3, Normal, Header, Footer, etc.) that you want to copy to your current document.
Click the Manage Styles icon on the Styles window.Ĥ.Open the Style window (press Shift+Ctrl+Alt+S or Alt+O+S).These types include Word formats and other file types such as Plain Text, Rich Text Format (RTF. A list of available file types appears on the right side of the screen. Choose Export from the items on the left side of the screen. Now to import styles from an old template to a new template/document, do the following: To export your document into another file format, follow these steps: Click the File tab.
You can save multiple templates (with different styles) as explained above in the Trusted Template folder.