View Single Post
 
Old 06-22-2017, 01:53 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I suspect that the error is self explanatory. The styleset (non standard) is available in the document in which it worked but is not available in the other documents in which it doesn't.

Frankly I wouldn't personally use style sets for this. I would create the style(s) that I wanted in a template (or document), then use the function to copy the style(s) from the template/document to the document under process (oDoc), apply the style(s) to the range(s) (oRng) as required and then reset the range to show the style settings that you have applied.

This code below is for one style, but you can sequentially copy other named styles similarly and move the range to its new location before applying them.

Code:
Dim oSource As Document
Const strStyle As String = "AsideStyle"    'The style to copy
    'open the template with the styles to be copied to the document
    Set oSource = Documents.Open _
                  (FileName:="C:\Path\TemplateName.dot", _
                   Visible:=False)

    Application.OrganizerCopy Source:= _
                              oSource.FullName, Destination:= _
                              oDoc, _
                              Name:=strStyle, _
                              Object:=wdOrganizerObjectStyles
    With oRng    'apply the style to the range
        .Style = strStyle
        .Font.Reset
        .ParagraphFormat.Reset
    End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote