• How to Find the Hard Drive Volume Label (VBA/Excel 97 and >)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » How to Find the Hard Drive Volume Label (VBA/Excel 97 and >)

    Author
    Topic
    #391585

    hello Loungers

    I used to have a code snipit that would get me the Hard Disk Drive label, the string that appears in FDisk, or in Windows Explorer Properties under Label, but I don’t have it any more.

    Does anyone have such code?

    Thanks In Advance.

    Wassim

    Viewing 0 reply threads
    Author
    Replies
    • #699958

      From API-Guide:

      Private Declare Function GetVolumeInformation Lib “Kernel32” Alias “GetVolumeInformationA” (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
      Private Sub Form_Load()
      ‘KPD-Team 1998
      ‘URL: http://www.allapi.net/
      ‘E-Mail: KPDTeam@Allapi.net
      Dim Serial As Long, VName As String, FSName As String
      ‘Create buffers
      VName = String$(255, Chr$(0))
      FSName = String$(255, Chr$(0))
      ‘Get the volume information
      GetVolumeInformation “C:”, VName, 255, Serial, 0, 0, FSName, 255
      ‘Strip the extra chr$(0)’s
      VName = Left$(VName, InStr(1, VName, Chr$(0)) – 1)
      FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) – 1)
      MsgBox “The Volume name of C: is ‘” + VName + “‘, the File system name of C: is ‘” + FSName + “‘ and the serial number of C: is ‘” + Trim(Str$(Serial)) + “‘”, vbInformation + vbOKOnly, App.Title
      End Sub

      • #699964

        thankyou Kevein

        I will try to use your API, but I found the code just a second ago, and it looks like:

        Dir$(.LookIn, 8)

        where .LookIn can be coming from the Application.FileSearch .LookIn parameter, or a simple text such as “C:”.

        But maybe this will not work on all drives, so I’ll still test and see if the API is more accurate and universal for all drives.

        Thanks again.

        Wassim

        • #699966

          Actually, your Dir statement works just peachy. Why bother with the API:

          ?dir( “c:”,vbVolume) –> returns the ubiquitious “Local Disk” monicker for my humble C:

          (8 is the int equiv for the VBA constant vbVolume)

    Viewing 0 reply threads
    Reply To: How to Find the Hard Drive Volume Label (VBA/Excel 97 and >)

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

    Your information: