Results 1 to 13 of 13
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    capture file extension (2002)

    While I'm asking (begging) for help, let's go for another one...
    The FILENAME p field code place the entire path into a document.
    I'd like to be able to capture the file extension from this field instruction to be able to do some arithmetic on it...
    Is that at all possible?

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

    Re: capture file extension (2002)

    There are no string manipulation fields such as InStr, Mid and Right available for use in fields, so I don't think you can do it in a field itself. Depending on what exactly you want to accomplish, it may be possible to use a VBA macro.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: capture file extension (2002)

    The file extension turns out to be encoded hex and I want to convert it in Word (I know I can in Excel) to decimal.

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

    Re: capture file extension (2002)

    You could do that in VBA code.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: capture file extension (2002)

    Maybe YOU could, but not me. Don't know even enough VBA to be dangerous.
    Ideally, if I could take the path and then pull the extension, that would be great.
    But, I'd even take a message box to input the hex and result in text output in the Word doc that was the decimal.

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

    Re: capture file extension (2002)

    It's still not clear to me what you want to do with the converted extension. Do you want to put it somewhere in the document, or ...?

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: capture file extension (2002)

    Yes, I want to put it into the document in decimal form (from hex).

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

    Re: capture file extension (2002)

    And where in the document? In the header or footer, or at the top of the document, or at the current insertion point, or ...?

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: capture file extension (2002)

    Ideally, I'd like to print the file name with path, then allow the user to insert some text, then have the hex to decimal number after that...all of which would be in the footer.

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

    Re: capture file extension (2002)

    Sorry to keep on asking, but do you mean that you have Word documents whose extension is NOT .doc but something like .3F8A ?

  11. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: capture file extension (2002)

    Exactly.

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

    Re: capture file extension (2002)

    The following macro will add text to the footer, consisting of the full name of the document, some user-specified text and the decimal value of the extension:

    Sub AddFooter()
    Dim strUserText As String
    Dim strHex
    Dim lngDecimal As Long
    Dim intPos As String
    On Error Resume Next
    strUserText = InputBox("Enter custom text.")
    intPos = InStrRev(ActiveDocument.Name, ".")
    If intPos > 0 Then
    strHex = " &H" & Mid(ActiveDocument.Name, intPos + 1)
    lngDecimal = CLng(strHex)
    End If
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range = _
    ActiveDocument.FullName & vbTab & strUserText & vbTab & lngDecimal
    End Sub

  13. #13
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: capture file extension (2002)

    Thank you for your trouble, Hans. That macro works perfectly (as all of yours do).

    K

Posting Permissions

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