Tekforums

Chat => Entertainment & Technology => Topic started by: M3ta7h3ad on May 13, 2006, 10:25:37 AM

Title: Grabbing current username macro?
Post by: M3ta7h3ad on May 13, 2006, 10:25:37 AM
I am doing a little tweaking of an excel document we use in work. Basically want to automate the filling out of any fields I can.

Ive got the current time and date working fine, but theres a "packed by" box, which tends to be filled in with the initials of the person who opened it.

Is there anyway of getting this information from a macro? So the currently logged in user gets listed in the "Packed by" Field?
Title: Re:Grabbing current username macro?
Post by: madmax on May 13, 2006, 12:41:05 PM
ive done it the other way round quite a few times....

in that ive made a vb6 interface program and let that generate an excel sheet.
use that to generate replacement reports they get on the current system.


if you need some details lemme know,
but its as simple as declaring  xlapp as new excel.application and adding workbook and sheets to it.

anything you can do in excel you can call from vb6
Title: Grabbing current username macro?
Post by: Mardoni on May 13, 2006, 12:50:57 PM
I dont think you can pull the username from a macro but it is certainly avalible from an API call.
Title: Re:Grabbing current username macro?
Post by: M3ta7h3ad on May 13, 2006, 13:33:47 PM
:(

Its just an excel spreadsheet that gets sent out to our sales staff for them to email a copy in filled out when they need some more stationary and stuff :) Cant make it an application but just want it to grab the current windows login and shove it in the field :) so that when the packers print off the order sheet it gives their names there.
Title: Re:Grabbing current username macro?
Post by: BigSoy on May 14, 2006, 18:36:22 PM
Its available from the ENVIRON function in Excel.

Use something like this:


Function UserNameWindows() As String
    UserNameWindows = Environ("USERNAME")
End Sub


I dont have Excel on this box at the moment but I tried that in word and Im reasonably convinced the same thing is available in Excel.