Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Retrieving template name (WinXP/Word2003)

    Okay, I don't think this one is difficult, if you know how to do it, but it is complicated and since I *don't* know how, I'm asking for a little help, please!

    Our templates are called by reasonably standardised names that usually consist of a string of letters and numbers, then 'ver' and a number, one or two characters, which is the version. And .DOT on the end of course. There are, however, a few that don't have the version and some that don't follow this standard at all. I need to extract the name of the template without the version, and put it in the built-in document property 'Title'.

    So I think what I want is something that, on creating a new document from a template, says "take everything from the name of the attached template that is to the left of 'VER', or if no 'VER', take everything except .DOT - and paste the result to the builtindocumentproperty 'title' " - does that sound feasible?

    And if so, how would I go about doing it, please?!!

    Many thanks in advance!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving template name (WinXP/Word2003)

    You can use this function:

    Function GetTemplateName()
    Dim strTemplate As String
    Dim intPos As Integer
    strTemplate = ActiveDocument.AttachedTemplate
    If LCase(Right(strTemplate, 4)) = ".dot" Then
    strTemplate = Left(strTemplate, Len(strTemplate) - 4)
    End If
    intPos = InStrRev(StringCheck:=strTemplate, StringMatch:="ver", _
    Compare:=vbTextCompare)
    If intPos > 0 Then
    strTemplate = Left(strTemplate, intPos - 1)
    End If
    GetTemplateName = strTemplate
    End Function

    Warning: it's not foolproof: if the template name doesn't follow the standard, but still contains "ver", it will be mangled. For example, "Revert.dot" would yield "Re".

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving template name (WinXP/Word2003)

    Thanks, Hans, I'll try that!
    Beryl M


Posting Permissions

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