• How to display filename without extension

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » How to display filename without extension

    Author
    Topic
    #461574

    How to display the filename without extension by { filename }?
    Say, given a document named ‘MyDoc.docx”, how to show it as “MyDoc”?
    Armstrong

    Viewing 0 reply threads
    Author
    Replies
    • #1171671

      How to display the filename without extension by { filename }?
      Say, given a document named ‘MyDoc.docx”, how to show it as “MyDoc”?

      Same question as this topic from May: Filename Field Code options Word 2007 (Word). Unfortunately the answer was that you cannot display only a portion of the file name when using the FILENAME field.

      • #1171672

        Same question as this topic from May: Filename Field Code options Word 2007 (Word). Unfortunately the answer was that you cannot display only a portion of the file name when using the FILENAME field.

        Hi Jscher2000,
        Thanks for your fast response. I thought it could be attained by { quote }.
        Armstrong

        • #1171673

          Hi Jscher2000,
          Thanks for your fast response. I thought it could be attained by { quote }.
          Armstrong

          Hi Armstrong,

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

          Cheers,
          Paul Edstein
          [Fmr MS MVP - Word]

          • #1171683

            Hi Armstrong,

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

            Hi macropod,
            You’re the authority in the Field. Perhaps I should learn how to do it in VBA.
            Thanks.
            Armstrong

            • #1171769

              Hi macropod,
              You’re the authority in the Field. Perhaps I should learn how to do it in VBA.
              Thanks.
              Armstrong

              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
              [Fmr MS MVP - Word]

            • #1171924

              Hi Macropod,
              Thanks for your help. I need some time to study the Word macro.
              Armstrong

    Viewing 0 reply threads
    Reply To: Reply #1171683 in How to display filename without extension

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel