Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Domain Name

  Asked By: Robert    Date: Oct 28    Category: MS Office    Views: 618
  

I use the below formula to pull the current user name (and format in
caps) in a few places.

Format(Environ("username"), ">")

I was wondering if anyone new of a simple expression to pull the
current domain name.

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Isabella Campbell     Answered On: Oct 28

Try something like this:

Sub GetNetworkDomain()
Dim wsh
Set wsh = CreateObject("WScript.Network")
MsgBox wsh.UserDomain
End Sub

 
Answer #2    Answered By: Logan Bouchard     Answered On: Oct 28

I get an error can't create object.... is there a reference that needs to be
added?

 
Answer #3    Answered By: Aidyn Smith     Answered On: Oct 28

I think it's the "Microsoft Scripting Runtime" (scrrun.dll).

 
Answer #4    Answered By: Abbad Akhtar     Answered On: Oct 28

i have that one referenced.. still doesnt' work.. and cant find it in the object
browser.. ( wscript)

 
Answer #5    Answered By: Cais Nguyen     Answered On: Oct 28

userdomain is an environ element... try this and you can see what items you can
get from the environ... (modified from the help example

Sub environstring()

Dim EnvString, Indx, Msg, PathLen ' Declare variables.
Indx = 1 ' Initialize index to 1.
Do
EnvString = Environ(Indx) ' Get environment
' variable.
If Left(EnvString, 5) = "PATH=" Then ' Check PATH entry.
PathLen = Len(Environ("PATH")) ' Get length.
ThisWorkbook.Worksheets("sheet2").Range("A" & Indx).Value = EnvString
' Msg = "PATH entry = " & Indx & " and length = " & PathLen
' Exit Do
Else
Indx = Indx + 1 ' Not PATH entry,
ThisWorkbook.Worksheets("sheet2").Range("A" & Indx).Value = EnvString
End If ' so increment.
Loop Until EnvString = ""
If PathLen > 0 Then
MsgBox Msg ' Display message.
Else
MsgBox "No PATH environment variable exists."
End If

End Sub

 
Answer #6    Answered By: Jaspreet Kapoor     Answered On: Oct 28

I was able to copy and paste this as is
into a module and get it working.

 
Answer #7    Answered By: Elaine Stevens     Answered On: Oct 28


yes that's the object it's trying to create isn't it.. wscript.network... or
am i completely turned around..?

 
Answer #8    Answered By: Alexis Castillo     Answered On: Oct 28

Don't be too hard on him...when I program, I tend to use whatever is
handiest and easiest. Especially with vba sometimes I have to
branch out to other sources to quickly accomplish what I need.

For what it's worth, I'd say that most of my vba code projects have
some vbs code in them (sometimes vba just can't do certain things).

 
Didn't find what you were looking for? Find more on Domain Name Or get search suggestion and latest updates.




Tagged: