+ Reply to Thread
Results 1 to 5 of 5

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

  1. #1
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    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

  2. #2
    NickHK
    Guest

    Re: 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" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > 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
    >




  3. #3
    rjhare
    Guest

    Re: 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


  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    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

  5. #5
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1