Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Hong Kong
    Posts
    359
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How to display the filename without extension by { filename }?
    Say, given a document named 'MyDoc.docx", how to show it as "MyDoc"?
    Armstrong

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='armsys' post='786941' date='30-Jul-2009 22:24']How to display the filename without extension by { filename }?
    Say, given a document named 'MyDoc.docx", how to show it as "MyDoc"?[/quote]
    Same question as this topic from May: [topic="763113"]Filename Field Code options Word 2007 (Word)[/topic]. Unfortunately the answer was that you cannot display only a portion of the file name when using the FILENAME field.

  3. #3
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Hong Kong
    Posts
    359
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='jscher2000' post='786942' date='31-Jul-2009 13:45']Same question as this topic from May: [topic="763113"]Filename Field Code options Word 2007 (Word)[/topic]. Unfortunately the answer was that you cannot display only a portion of the file name when using the FILENAME field.[/quote]
    Hi Jscher2000,
    Thanks for your fast response. I thought it could be attained by { quote }.
    Armstrong

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='armsys' post='786944' date='31-Jul-2009 16:45']Hi Jscher2000,
    Thanks for your fast response. I thought it could be attained by { quote }.
    Armstrong[/quote]
    Hi Armstrong,

    Word's field coding abilities don't extend to string manipulation of the kind you're after.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Hong Kong
    Posts
    359
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='macropod' post='786945' date='31-Jul-2009 15:12']Hi Armstrong,

    Word's field coding abilities don't extend to string manipulation of the kind you're after.[/quote]
    Hi macropod,
    You're the authority in the Field. Perhaps I should learn how to do it in VBA.
    Thanks.
    Armstrong

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='armsys' post='786967' date='31-Jul-2009 21:09']Hi macropod,
    You're the authority in the Field. Perhaps I should learn how to do it in VBA.
    Thanks.
    Armstrong[/quote]
    Hi Armstrong,

    If you add the following code to the document's 'this Document' module, and insert a bookmark named 'FileName' wherever you want the filename to appear, it will insert/update the file's name (without the extension) at that location whenever the document is opened. If you want this to apply to all documents based on a given template, do the same to the template.
    Code:
    Private Sub Document_Open()
    Dim BmkNm As String, BmkRng As Range, FileName As String
    BmkNm = "FileName"
    FileName = ActiveDocument.Name
    If InStrRev(FileName, ".") > 0 Then FileName = Left(FileName, InStrRev(FileName, ".") - 1)
    If ActiveDocument.Bookmarks.Exists(BmkNm) Then
      Set BmkRng = ActiveDocument.Bookmarks(BmkNm).Range
      If BmkRng.Text = FileName Then Exit Sub
      BmkRng.Text = FileName
      ActiveDocument.Bookmarks.Add BmkNm, BmkRng
    Else
      MsgBox "Bookmark: " & BmkNm & " not found."
    End If
    Set BmkRng = Nothing
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Hong Kong
    Posts
    359
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Macropod,
    Thanks for your help. I need some time to study the Word macro.
    Armstrong

Posting Permissions

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