Results 1 to 3 of 3
  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

    Dynamic AddIns (Word97/SR2)

    Suppose you had a slew of about 40 useful templates, but you didn't want them to fire up each time Word loaded. You'd not want them in the Startup folder, because you'ld wait days while Word initialised each one of them.

    You'ld probably want to add them in ONLY when they were needed.

    So, I thought, a Toolbar menu (View, Toolbars, Customize, Commands, New Menu etc.) and a button for each application. When I want to fire up WbWrd, I click on my toolbarmenu button, slide down to WbWrd, and voila! as they say in the UK, the WbWrd application is added-In, and its toolbar is available for use.

    So, the first thing we need is a general function to locate the most recent one of a set of templates in a folder. (I keep all versions of the WbWrd template in C:GreavesproductsWbWrd, I keep all versions of the PClip template in C:GreavesproductsPClip, etc), and that procedure is listed below. It seems to work quite well for my purposes.


    But then I realised that each button on the "Add" toolbar menu would have to refer to a Macro, and I didn't want to write 40 macros called AddInWbWrd, AddInPClip, etc.


    I'm mulling over the possibility of having an AutoExec macro obtain every sub-folder name within C:GreavesProducts, but that suggests taking more time than it would to just have the latest version in my StartUp folder.


    The list of sub-folders (WbWrd, PClip etc) is fairly static; say 40 folders in five years, so assembling a set of 40 small macros, each of which calls the function "strAddInLatest" with the appropriate hard-wired folder name isn't all that bad.


    But am I missing a better way?


    <pre>Public Function strAddInLatest(ByVal strRoot As String) As String
    ' The strRoot defines an absolute path.
    ' Locate the most recent template (*.DOT) in that path and
    ' add it into the available application set
    ' If the result string has LEN=0 then success
    ' Else the result string is an error message.

    Dim strResult As String
    strResult = ""

    ' Force a trailing slash
    If Right$(strRoot, 1) <> Application.PathSeparator Then
    strRoot = strRoot & Application.PathSeparator
    Else
    End If

    Dim strFile As String
    Dim dtlatest As Date
    strFile = Dir(strRoot & "*.dot", vbNormal)
    If strFile = "" Then
    strAddInLatest = "Not a single template could be found. (" & strRoot & ")"
    Else

    dtlatest = FileDateTime(strRoot & strFile)
    While strFile <> ""
    If dtlatest < FileDateTime(strRoot & strFile) Then
    dtlatest = FileDateTime(strRoot & strFile)
    strResult = strRoot & strFile
    Else
    End If
    strFile = Dir
    Wend

    If strResult <> "" Then
    AddIns.Add FileName:=strResult, Install:=True
    strAddInLatest = ""
    Else
    strAddInLatest = "Not one of the files was the latest! (" & strRoot & ")"
    End If
    End If

    'Sub TESTstrAddInLatest()
    ' MsgBox strAddInLatest("C:GreavesProducts")
    'End Sub

    End Function
    </pre>


  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Eugene, Oregon, USA
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic AddIns (Word97/SR2)

    I think you can avoid having 40 different macros each called by a separate menu item if you use the "tag" property of the commandbarcontrol.

    Assign each menu item to the same macro via the .OnAction and assign each item a different .Tag property (corresponding to the name of the subfolder you want to hit). In that one macro, you could then retrieve that the tag as
    strRoot = CommandBars.ActionControl.Tag

  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: Dynamic AddIns (Word97/SR2)

    > assign each item a different .Tag property

    Hubert, thanks for this. I keep forgetting about the .Tag of an object!

    I had already set up 40+ small macros, and it seems to work well. Tonight I'll try the .Tag trick; I can't see why it shouldn't work, and I much prefer a generalised solution!

Posting Permissions

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