PDA

View Full Version : Solved: Modify code to close workbook if opened on wrong computer



Barryj
04-19-2011, 02:11 AM
I have found this code on the net and have been trying to alter it to have it close the work book if the computer name does not match that in the code.

I have not had much luck and was hoping some one may be able to lend a hand.

Private Sub Workbook_Open()
MsgBox Environ("ComputerName")
If Environ("ComputerName") <> UCase("Authorized PC Name") Then
MsgBox "Sorry No Go!" & vbCrLf & "Wrong computer!"
End
Else
'** Do your thing here
MsgBox "Proceed"
End If
End Sub




The idea is if somebody copies the workbook to another computer it will not open for them, it is for use on only one computer.

Thanks for any assistance

Bob Phillips
04-19-2011, 02:32 AM
Does this do it



Private Sub Workbook_Open()
If Environ("ComputerName") <> UCase("Authorized PC Name") Then
MsgBox "Sorry No Go!" & vbCrLf & "Wrong computer!"
Me.Close SaveChanges:=False
Else
'** Do your thing here
MsgBox "Proceed"
End If
End Sub

Barryj
04-19-2011, 02:41 AM
That seems to be working, thanks very much xld, I will mark it as solved.

Thanks again.