0

I found one the function of VBA EXCEL which gives me My System's HardDrive Serial No. in hex format.

okay, I have active Microsoft Excel 16.0 Object Library on my system.

when I have run the same code on my friend's system, I got an error of

Error Loading DLL

While checking his systems references, I found He has Active Microsoft Excel 12.0 Object Library. Which is a clear case of Late Binding and Early Binding? (I thought So....!)

Here's the Code of the function that I have got from the random forum,

Function HdNum() As String

    Dim fsObj   As Object

    Dim drv  As Object

    Set fsObj = CreateObject("Scripting.FileSystemObject")

    Set drv = fsObj.Drives("C")

    HdNum = VBA.Hex(drv.serialnumber)

End Function

can u please guide me what is the problem actually?

0

1 Answer 1

1

Anyhow, I got the solution to this problem.

The problem I was facing because my friend has installed 64bit Version of MS Office. and to we all have an idea how coding differs in VB7 which is implied to the 64bit version of MS office.

Here below I'm providing the code to this facility to generate HardDisk Serial no. from any of the version of Office.

In the module paste this following code

#If VBA7 Then
Private Declare PtrSafe Function GetVolumeInformation Lib _
"kernel32.dll" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Integer, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
#Else
Private Declare Function GetVolumeInformation Lib _
"kernel32.dll" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Integer, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
#End If

Public Function DriveSerialNumber(ByVal Drive As String) As Long

Dim lAns As Long
Dim lRet As Long
Dim sVolumeName As String, sDriveType As String
Dim sDrive As String

sDrive = Drive
If Len(sDrive) = 1 Then
    sDrive = sDrive & ":\"
ElseIf Len(sDrive) = 2 And Right(sDrive, 1) = ":" Then
    sDrive = sDrive & "\"
End If

sVolumeName = VBA.String$(255, Chr$(0))
sDriveType = VBA.String$(255, Chr$(0))
lRet = GetVolumeInformation(sDrive, sVolumeName, 255, lAns, 0, 0, sDriveType, 255)
DriveSerialNumber = lAns

End Function

Function HdNum() As String
    HdNum = VBA.Hex(DriveSerialNumber("C:\"))
End Function

Sub HD()
    MsgBox HdNum
End Sub

Thank you Guys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.