Unique computer ID verification prior to opening workbook using VBA

kstrick9

Board Regular
Joined
Nov 5, 2012
Messages
122
Fairly new to VBA code here. I have a condition setup (under "This Workbook") upon opening a spreadsheet to verify a computer's predetermined motherboard serial number that will shut the Excel workbook down if the numbers do not match. This works fine. What I'd like to do is to add a second condition that will allow a password to be entered in a textbox if the numbers do not match so that the serial number condition could be manually overridden, if necessary. If the serial number and the password are incorrect the workbook automatically closes. Thanks in advance for any help!

Here is the code that works:

Private Sub Workbook_Open()
If CreateObject("Scripting.FileSystemObject").GetDrive("C:\").SerialNumber <> "-XXXXXXX" Then ActiveWorkbook.Close False
End Sub

Here is what I am attempting to do that is not functioning properly - need to add a textbox to enter a password to override an incorrect serial number

Private Sub Workbook_Open()
If CreateObject("Scripting.FileSystemObject").GetDrive("C:\").SerialNumber <> "-XXXXXXX" Then
Dim Rng
Rng = InputBox("aaaaaa")
If Rng <> "aaaaaa" Then ActiveWorkbook.Close False
End Sub
 
One last question: How would I go about adding a 2nd serial number using "or" in VBA. In other words, if it wasn't this serial number or a 2nd number, then it would prompt the password text box. Thanks
 
Upvote 0
Kyle123, thanks. DataSafeXL may be a solution to protect sheets and VBA code.

For anyone that may be interested in using this code, here it is (new to posting and not sure how to put code in boxes...sorry):

Private Sub Workbook_Open()
Dim Rng As String
If CreateObject("Scripting.FileSystemObject").GetDrive("C:").SerialNumber <> "-get using code below and manually enter" Then
Rng = InputBox("Conflicting Computer ID numbers. Please enter password to gain access to program:")
If LCase(Rng) <> "yourpassword" Then ActiveWorkbook.Close False
End If
End Sub

Use this to get serial number:

Sub ShowDriveInfo()
Dim fs, d, s, t
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)))
Select Case d.DriveType
Case 0: t = "Unknown"
Case 1: t = "Removable"
Case 2: t = "Fixed"
Case 3: t = "Network"
Case 4: t = "CD-ROM"
Case 5: t = "RAM Disk"
End Select
s = d.SerialNumber
Range("A1") = s
End Sub

Very
good, what about macro for doing the same in Powerpoint slideshow to verify computer ID when a button is clicked, and if the ID is not the same the user is directed to another slide in the slideshow for more information? Please help...
 
Upvote 0
Kyle123, thanks. DataSafeXL may be a solution to protect sheets and VBA code.

For anyone that may be interested in using this code, here it is (new to posting and not sure how to put code in boxes...sorry):

Private Sub Workbook_Open()
Dim Rng As String
If CreateObject("Scripting.FileSystemObject").GetDrive("C:\").SerialNumber <> "-get using code below and manually enter" Then
Rng = InputBox("Conflicting Computer ID numbers. Please enter password to gain access to program:")
If LCase(Rng) <> "yourpassword" Then ActiveWorkbook.Close False
End If
End Sub

Use this to get serial number:

Sub ShowDriveInfo()
Dim fs, d, s, t
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)))
Select Case d.DriveType
Case 0: t = "Unknown"
Case 1: t = "Removable"
Case 2: t = "Fixed"
Case 3: t = "Network"
Case 4: t = "CD-ROM"
Case 5: t = "RAM Disk"
End Select
s = d.SerialNumber
Range("A1") = s
End Sub

hi guys! how do i enter this in excel te get the serial of my laptop? i need this to protect my excel files. thanks in advance for help!
 
Upvote 0

Forum statistics

Threads
1,226,848
Messages
6,193,315
Members
453,790
Latest member
yassinosnoo1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top