environ("username")
application.UserName
For the username associated with the operating system, you can use the Environ function...
Code:environ("username")
For the username associated with the application, you can use the UserName property of the Application object...
Code:application.UserName
Hope this helps!
[FONT=Courier New][COLOR=darkblue]Sub[/COLOR] SelectUserFromSlicer()
[COLOR=darkblue]Dim[/COLOR] oSlicerItem [COLOR=darkblue]As[/COLOR] SlicerItem
[COLOR=darkblue]Dim[/COLOR] sUserName [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
Application.ScreenUpdating = [COLOR=darkblue]False[/COLOR]
sUserName = Environ("username") [COLOR=green]'or Application.UserName[/COLOR]
[COLOR=darkblue]With[/COLOR] ThisWorkbook.SlicerCaches("Slicer_User") [COLOR=green]'change the slicer name accordingly[/COLOR]
.ClearManualFilter
[COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
[COLOR=darkblue]Set[/COLOR] oSlicerItem = .SlicerItems(sUserName)
[COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
[COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] oSlicerItem [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
[COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oSlicerItem [COLOR=darkblue]In[/COLOR] .SlicerItems
[COLOR=darkblue]If[/COLOR] UCase(oSlicerItem.Name) <> UCase(sUserName) [COLOR=darkblue]Then[/COLOR]
oSlicerItem.Selected = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Next[/COLOR] oSlicerItem
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
Application.ScreenUpdating = [COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]