Author Topic: Grabbing current username macro?  (Read 4558 times)

Grabbing current username macro?
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?

  • Offline madmax

  • Posts: 782
  • Hero Member
Re:Grabbing current username macro?
Reply #1 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

  • Offline Mardoni

  • Posts: 2,636
  • Global Moderator
  • Hero Member
  • On the Sofa, probably ;)
Grabbing current username macro?
Reply #2 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.

Re:Grabbing current username macro?
Reply #3 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.

  • Offline BigSoy

  • Posts: 1,353
  • Hero Member
  • They sicken of the calm, who knew the storm.
Re:Grabbing current username macro?
Reply #4 on: May 14, 2006, 18:36:22 PM
Its available from the ENVIRON function in Excel.

Use something like this:

Code: [Select]

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.
"Within your 'purview'? Where do you think you are, some f**king regency costume drama? This is a government department, not some f**king Jane f**king Austen novel!"

0 Members and 1 Guest are viewing this topic.