office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access Excel VBA通過API修改硬盤捲標(Disk Label)

2020-02-26 08:00:00
zstmtony
原創
398

Access Excel VBA通過API修改硬盤捲標(Disk Label) 俗稱硬盤標籤 或硬盤彆名--Change the Drive Volume Label



調用瞭: Windows 繫統 API



Option Explicit

Private Declare Function SetVolumeLabel Lib "kernel32" Alias _
   "SetVolumeLabelA" (ByVal lpRootPathName As String, _
   ByVal lpVolumeName As String) As Long
 
Public Function gf_ChangeDiskLabel(strDriver As String, strNewDriveLabel As String) As Boolean
 
Dim lngRet As Long  
 
On Error Resume Next
lngRet = SetVolumeLabel(strDriver , strNewDriveLabel ) 'office-cn.net ChangeDiskLabel = (lngRet <> 0)
    
End Function


'使用方法

'ChangeDiskLabel("F:", "Office中國數據盤")



vb.net方法

        Dim int As Integer = 0
        For Each di As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
            Try
                di.VolumeLabel = "Test" & int.ToString
                int += 1
            Catch ex As Exception
 
            End Try
        Next

分享