PDA

View Full Version : User name pulled from Windows



ozzyb77
02-17-2012, 08:07 AM
I have the below AVB script to pull through user names from Windows into a particular column (column C). This works fine for when I open the document however when I opened the document from a colleagues PC it changed my entry (user name) to his name. Ideally what i want is anything I enter to be saved and then when a colleague opens the document to enter data it doesn't change the information i have enetered and allows him to record his data.

Is there something missing from the script below?

Select Case UCase(NameType)
Case Is = "OFFICE", "1"
GetName = Application.uSERNAME
Exit Function
Case Is = "WINDOWS", "2"
GetName = Environ("UserName")
.Save
Exit Function
Case Else
GetName = CVErr(xlErrValue)
.Save
End Select

End Function

Thanks
Ozzy

Bob Phillips
02-17-2012, 09:28 AM
Where is that code located?

Paul_Hossler
02-18-2012, 08:15 AM
This works fine for when I open the document however when I opened the document from a colleagues PC it changed my entry (user name) to his name.

That would be what I would expect if you opened the document from another PC.

If the act of opening overwrites your original data, I think you'll need to change the approach to not overwrite data that shouldn't

Is this for some kind of log 'file' where data just keeps on getting added to the end of a list?

Maybe some more details would help.

Paul

ozzyb77
02-20-2012, 04:54 AM
Hi, thanks for the replies.

Yes the document is a shared file to which members of the team update on a daily basis. I found the script on line and not experienced enough on VBA's and still learning so apologies for my lack of knowledge.

Is there a way to add to the script so the file saves everytime and then when the macro is run it doesn't over write the existing data or is a macro designed to change the whole spreadsheet everytime its run?