Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Styles- organiser (Word97SR2)

    The code below generates a syntax error.

    I'm surprised.

    I'd always thought that I was able to copy a style from an added-in template, from within Word97 using Format, Styles, Organiser, (close Normal.dot), open the addin template etc etc etc.

    I think I was wrong.

    Organiser OPENS a template, any template, it just happens to be available as an add-on at the moment. That's co-incidental.


    I'm still surprised that an added-in template (.DOT rather than .WLL) won't yield its styles to investigation!



    <pre>Public Function styStyleFromAnyGlobalTemplate(doc As Document, strStyleName As String) As Style
    ' Procedure : styStyleFromAnyGlobalTemplate
    ' Description: Determine if a style is/has been defined in ANY GLOBAL template.
    ' Copyright: Chris Greaves Inc.
    ' Inputs: Document, style name
    ' Returns: STYLE
    ' Assumes: None.
    ' Side Effects: None.
    ' Tested: By the calls shown below.
    Set styStyleFromAnyGlobalTemplate = Nothing
    Dim i As Integer
    For i = 1 To Application.AddIns.Count
    Dim docAddIn As AddIn
    Set docAddIn = Application.AddIns(i)
    If docAddIn.Installed Then

    Set styStyleFromAnyGlobalTemplate = Nothing
    Dim sty As Style
    For Each sty In docAddIn.Styles ' <<< method or data member not found
    If strStyleName = sty.NameLocal Then
    Set styStyleFromAnyGlobalTemplate = sty
    Exit Function
    Else
    End If
    Next sty

    Else
    End If
    Next i
    'Sub TESTstyStyleFromAnyGlobalTemplate()
    'Dim sty As Style
    'Set sty = styStyleFromAnyGlobalTemplate(activedocument, "aaabc")
    'Set sty = styStyleFromAnyGlobalTemplate(activedocument, "aaaaz")
    'End Sub
    End Function
    </pre>


  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Styles- organiser (Word97SR2)

    Hi Chris,

    Long time no speak - hope all is well.

    "Styles" is not a member of AddIn; that's probably the cause of the syntax error.

    You might need to Dim two different docAddIn variables - one as AddIn (to test for Installed), and one as Document (to access its Styles collection).

    Gary

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles- organiser (Word97SR2)

    Gary, thanks for the reply.


    > "Styles" is not a member of AddIn; that's probably the cause of the syntax error.

    Correct.

    > You might need to Dim two different docAddIn variables - one as AddIn (to test for Installed), and one as Document (to access its Styles collection).


    I made a quick essay, but the code below yields me a run-time error '13 Type Mismatch'


    <pre> Dim docAddIn As AddIn
    Dim docDoc As Document ' <<<<< as document
    Set docAddIn = Application.AddIns(i)
    Set docDoc = Application.AddIns(i)
    If docAddIn.Installed Then

    Set styStyleFromAnyGlobalTemplate = Nothing
    Dim sty As Style
    For Each sty In docDoc.Styles
    </pre>



    If I make the docDoc generic:

    <pre> Dim docAddIn As AddIn
    Dim docDoc ' <<<<< generic (no, it's called variant, isn't it?)
    Set docAddIn = Application.AddIns(i)
    Set docDoc = Application.AddIns(i)
    If docAddIn.Installed Then

    Set styStyleFromAnyGlobalTemplate = Nothing
    Dim sty As Style
    For Each sty In docDoc.Styles

    </pre>


    I get a '438 Object doesn't support this property or method' on the "For Each sty"




    I suspect that the truth is something like this:

    When a file that just so happens to be a template is referenced as an AddIn, there's some special part of VBA interpreter that can go in through a separate door to access the program code, such as the functions and procedures.

    When a file that just so happens to be a template is referenced as an Template/Document, there's some special part of VBA interpreter, different from the former part, that can go in through a different door to access the program code, such as the functions and procedures AND the styles (and whatever else).

    If I actually Open the template (which is what I'm doing in Format, Styles, organiser), then it is the second chunk of code that opens the door to ALL the goodies within the template.

    If I refer to the template as an Add-In, then the deprived (sic!) code comes into play, and it is only allowed to get as far as pointers-to-procedures.


    I don't say that that is what happens, but it fits the behaviour for now.



    If I absolutely had to get those styles, I'd use the Name property of the Addin, then I'd open the template, search for styles, and move on to the next one. For the current exercise it's not worth it.



    Background: The user gets to nominate a style to be used, and if it doesn't exist, I'll create a style with that name and leave it to the user to clarify the definition after my work is done. I'd thought to simplify the user's task by searching for any styles with that name available to me. The ActiveDocument, its Attached template, Normal.Dot were obvious places to search, then I thought [bright idea] "What about the styles in all available AddIns?" [/bright idea].

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Styles- organiser (Word97SR2)

    > If I absolutely had to get those styles, I'd use the Name property of the Addin, then I'd open the template, search for styles,
    > and move on to the next one. For the current exercise it's not worth it.

    Just in case it's worth it for someone else, using all 3 objects does seem to work:
    <pre>Sub GetToAddInStyles()
    Dim add As AddIn, tmp As Template, doc As Document
    For Each add In Application.AddIns
    If LCase(Right(add.Name, 4)) = ".dot" Then
    Set tmp = Templates(add.Path & Application.PathSeparator & add.Name)
    Set doc = Documents.add(Template:=tmp.FullName, Visible:=False)
    Set tmp = Nothing
    Stop 'do stuff with the styles collection
    doc.Close SaveChanges:=wdDoNotSaveChanges
    Set doc = Nothing
    End If
    Next
    If Not add Is Nothing Then Set add = Nothing
    End Sub</pre>

    Not elegant, but it's only a lunch hour quickie... oh, I forgot to test for .Installed; make sure to add that. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles- organiser (Word97SR2)

    I've thought even more about this, having had to make two peak-hour trips across the top of Toronto.

    I suppose that if I view the AddIn collection as an avenue to Procedure code then there's no reason to treat the collection as having any significance in terms of Styles.

    If OTOH I treat the Addins Collection as a "set of really useful stuff that I've worked on" then I might reasonable want to access Styles as well as Procedures.


    I remember the Grand Debates of Styles a year or two back.

    I suspect that the correct approach, especially in a Real Shop, is to have templates that contain Styles, correctly organised and updateable, and a different set of templates that contain Procedure Code. In fact, I rather like the idea of having Procedural templates and Style templates, since most often (but not always) what I'm DOING to data is a separate matter from how I want the processed data ("Information") to APPEAR to the user. Furthermore, there may often be cases (Update Styles On Open) where the same data must appear in a different format to different users.


    That now suggests to me that I should treat the AddIn collection as a place for templates that contain Procedures, and that I shouldn't, really, be snooping around the AddIns collection looking for handy Styles.

    Most of my Application templates only have styles that are residual from Normal.DOT anyway.

  6. #6
    Lounger
    Join Date
    Jan 2001
    Location
    Kingwood, Texas, USA
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles- organiser (Word97SR2)

    I use the following code snippet to get at things in an Add-In template:

    Dim Tplt As Template
    For Each Tplt In Templates
    If Tplt.Name = "MyTemplate.dot" Then Exit For 'Of course, you do need to know the name of the Add-In template!
    Next Tplt

    'You can now use Tplt to get at whatever is stored in your Add-In, for example:

    Tplt.AutoTextEntries("My AutoText").Insert Where:= _
    Selection.Range, RichText:=True

    Hope this helps!

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles- organiser (Word97SR2)

    Margot, thanks for this. It confirms my belief that one can't access Styles through Organizer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •