• Determining File Types from Extension (Excel 2000 SR-1)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Determining File Types from Extension (Excel 2000 SR-1)

    Author
    Topic
    #399351

    Hello,

    Is there an easy way to get the full description of the file type from just the three letter extension? I know that windows stores this information, I need to access it in order to present to the user of the spreadsheet.

    Thanks,

    Viewing 3 reply threads
    Author
    Replies
    • #770706

      Feel free to play with the attached.

    • #770707

      Feel free to play with the attached.

    • #770708

      If scripting is allowed on your user’s systems, the following code will read the description from the registry:

      Function GetType(Extension As String) As String
      Dim oShell As Object
      Dim strExt As String
      Dim strKey As String

      On Error GoTo ErrHandler

      Set oShell = CreateObject(“WScript.Shell”)
      strExt = Extension
      If Not (Left(strExt, 1)) = “.” Then
      strExt = “.” & strExt
      End If
      strKey = oShell.RegRead(“HKEY_CLASSES_ROOT” & strExt & “”)
      GetType = oShell.RegRead(“HKEY_CLASSES_ROOT” & strKey & “”)

      ErrHandler:
      Set oShell = Nothing
      End Function

      Examples:
      GetType(“doc”) or GetType(“.doc”) will return “Microsoft Word Document”
      GetType(“dok”) will return a blank string, since .dok is not a registered file type.

      (My code is a shameless ripoff from post 279025 by R2)

      • #771837

        Thank you for your help. This is exactly what I was looking for.

        Regards,

      • #771838

        Thank you for your help. This is exactly what I was looking for.

        Regards,

    • #770709

      If scripting is allowed on your user’s systems, the following code will read the description from the registry:

      Function GetType(Extension As String) As String
      Dim oShell As Object
      Dim strExt As String
      Dim strKey As String

      On Error GoTo ErrHandler

      Set oShell = CreateObject(“WScript.Shell”)
      strExt = Extension
      If Not (Left(strExt, 1)) = “.” Then
      strExt = “.” & strExt
      End If
      strKey = oShell.RegRead(“HKEY_CLASSES_ROOT” & strExt & “”)
      GetType = oShell.RegRead(“HKEY_CLASSES_ROOT” & strKey & “”)

      ErrHandler:
      Set oShell = Nothing
      End Function

      Examples:
      GetType(“doc”) or GetType(“.doc”) will return “Microsoft Word Document”
      GetType(“dok”) will return a blank string, since .dok is not a registered file type.

      (My code is a shameless ripoff from post 279025 by R2)

    Viewing 3 reply threads
    Reply To: Determining File Types from Extension (Excel 2000 SR-1)

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

    Your information: