Machine User Name
Machine User Name
Machine User Name
Machine User Name
Machine User Name
Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name
Machine User Name Machine User Name
Machine User Name
Go Back  Xtreme Visual Basic Talk > > > > Machine User Name


Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2017, 06:02 PM
cacody cacody is offline
Junior Contributor
 
Join Date: Apr 2011
Location: Scottsdale AZ
Posts: 323
Default Machine User Name


I have a macro that retrieves a computer's machine user name, and puts it in cell C60, but it is for a PC only. I found code that captures the machine user name for a Mac also, but I'm not sure it works since I don't have / use a Mac. Can anyone verify that the macro below works for a Mac? The Excel file would be operating on a Mac using Office for Mac in a Windows environment. If not, how do I capture the Mac user name? Thanks.
Code:
Private Sub Workbook_Open()
Dim sUserName As String, GetUserNameMac As Variant, ws As Worksheet
Dim sMyScript As String

If ws.Range("C60") = "" Then
    sUserName = Environ$("username")
    ws.Range("C60") = sUserName
    If sUserName Is Nothing Then
        sMyScript = "set userName to short user name of (system info)" & vbNewLine & "return userName"
        GetUserNameMac = MacScript(sMyScript)
    If Not GetUserNameMac Is Nothing Then
        ws.Range("E60") = GetUserNameMac
    End If
End If
End Sub
Reply With Quote
  #2  
Old 03-06-2017, 08:34 AM
MPiMachine User Name MPi is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Dec 2001
Location: Quebec
Posts: 1,000
Default

Hi,

I think you could use conditional compilation like this
Code:
#If Win64 Or Win32 Then
   sUserName = Environ$("username")
#Else
    GetUserNameMac = MacScript(sMyScript)
#End If
__________________
MPi²
Reply With Quote
  #3  
Old 03-07-2017, 02:10 PM
cacody cacody is offline
Junior Contributor
 
Join Date: Apr 2011
Location: Scottsdale AZ
Posts: 323
Default

MPi, thanks. I'll use this and ask a friend with a Mac to test it for me.
Reply With Quote
Reply

Tags
mac, user, getusernamemac, susername, machine, smyscript, ws.rangec60, macro, dim, string, username, info, capture, macscriptsmyscript, workbook_open, vbnewline, private, system, short, ws.rangee60, return, environ$username, worksheet, set, variant


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Machine User Name
Machine User Name
Machine User Name Machine User Name
Machine User Name
Machine User Name
Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name Machine User Name
Machine User Name
Machine User Name
 
Machine User Name
Machine User Name
 
-->