Get logged on username in Excel VBA - not the account running Excel (using RunAs) Get logged on username in Excel VBA - not the account running Excel (using RunAs) vba vba

Get logged on username in Excel VBA - not the account running Excel (using RunAs)


The basic approach is to execute the shell with a "run as" parameter.

  • have you taken a look at this
  • also look here

This is code ripped from the ms sight and is just here to make sure that the next guy or gal who comes by has a quick reference.

Sub RegisterFile(ByVal sFileName As String)ShellExecute 0, "runas", "cmd", "/c regsvr32 /s " & """" & sFileName & """", "C:\", 0 'SW_HIDE =0End Sub

As an aside if you only need the account for access to a SQL server, you should be able to just set the account within the connection string in your vba MACRO. I've done that for an Oracle DB in the past.