我找到了一个VBA EXCEL的功能,它以十六进制格式给我My System的HardDrive序列号。
好吧,我的系统上有活动的Microsoft Excel 16.0对象库。
当我在朋友的系统上运行相同的代码时,我收到了错误
加载DLL时出错
在检查他的系统引用时,我发现他有Active Microsoft Excel 12.0对象库。这是晚期绑定和早期绑定的明显案例? (我是这么想的....!)
这是我从随机论坛获得的函数代码,
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
你能指导我实际上是什么问题吗?
无论如何,我得到了解决这个问题的方法。
我遇到的问题是因为我的朋友安装了64位版本的MS Office。并且我们都知道VB7中的编码有何不同,这与64位版本的MS Office有关。
下面我将为此工具提供代码以生成HardDisk Serial no。从任何版本的Office。
在模块中粘贴以下代码
#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
感谢你们。