ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Only opening a workbook by User Name or Machine Name??? (https://www.excelbanter.com/excel-programming/364784-only-opening-workbook-user-name-machine-name.html)

Simon Lloyd[_792_]

Only opening a workbook by User Name or Machine Name???
 

Hi all, is there a way of capturing either the User name or Machine name
that the workbook is being opened on?, i would like to send a workbook
to some people but do not want to allow them to open the workbook on
any other machine than their own so if their machine is called Office1
then they can only open it on there else close the workbook, all the
network users are narrowed to being able to log on on one machine only
i do not want them taking the workbook home!, single machine users
outside the company i would like them to only open the workbook on the
machine that recieved the e-mail with the workbook in.

probably an impossible task..........but maybe just maybe one of you
may have an angle on this!

Regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553507


NickHK

Only opening a workbook by User Name or Machine Name???
 
Simon,
For the computer name, see the earlier post today titled "computer_name".
As for the user name, Application.UserName gives you name shown in Help
About Excel..

Or for the logged in user:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Private Sub CommandButton1_Click()
Dim strUserName As String
Dim RetVal As Long
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
RetVal = GetUserName(strUserName, 100)
'strip the rest of the buffer
Debug.Print Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
End Sub

How you decide which is valid is up to you.

NickHK

"Simon Lloyd"
wrote in message
...

Hi all, is there a way of capturing either the User name or Machine name
that the workbook is being opened on?, i would like to send a workbook
to some people but do not want to allow them to open the workbook on
any other machine than their own so if their machine is called Office1
then they can only open it on there else close the workbook, all the
network users are narrowed to being able to log on on one machine only
i do not want them taking the workbook home!, single machine users
outside the company i would like them to only open the workbook on the
machine that recieved the e-mail with the workbook in.

probably an impossible task..........but maybe just maybe one of you
may have an angle on this!

Regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile:

http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553507




rjhare[_3_]

Only opening a workbook by User Name or Machine Name???
 
I would probably use a bit of API wizardry:

' API dec
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

' Function:

Function GetUserName() As String
Dim lpBuff As String * 25
Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Function

' Useage:

Dim strCurrentUser as String
strCurrentUser = GetUserName
If strCurrentUser < "Simon Lloyd" Then
MsgBox "You are not authorised to view this Workbook"
Else
' open
End if

HTH

Haresoftware


Simon Lloyd[_793_]

Only opening a workbook by User Name or Machine Name???
 

Thanks for the replies, i have no idea what API is and i would not be at
liberty to install anything on anyones machine (it would be a nightmare
too!), does the get user name not pick up on the machine name?, does
the user of Excel always have a user name? if so then the get user name
would be fine, i would just have to send a workbook to each user to
collect their user name and then code their name in, am i right in
assuming that when it does Get UserName i can have that user name
stored in a cell so when i get the workbook back i can copy the name
out from that?

regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553507


Simon Lloyd[_800_]

Only opening a workbook by User Name or Machine Name???
 

Hi all, Does anyone know if every time excel is opened on a machine if
it has a user or machine name?, i would still like to achieve my
previous post above!

regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553507



All times are GMT +1. The time now is 09:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com