-2
私はまだVBAはあまりよくありません。 If NamePart =
で始まり、=
記号が強調表示されている行を指すタイトルのエラーが表示されます。誰でも知っている理由は?VBA:タイプの不一致
Public Enum NamePart
EnvironmentDefined
FullName
FirstName
LastName
End Enum
Public Function GetUser(Optional ByVal part As NamePart = EnvironmentDefined) As String
Dim result As String
Dim sysInfo As Object
Dim userInfo As Object
If NamePart = EnvironmentDefined Then
GetUser = Environ$("USERNAME")
Exit Function
End If
Set sysInfo = CreateObject("ADSystemInfo")
Set userInfo = GetObject("LDAP://" & sysInfo.UserName)
Select Case NamePart
Case FullName
result = userInfo.FullName
Case FirstName
result = userInfo.GivenName
Case LastName
result = userInfo.LastName
Case Else
result = Environ$("USERNAME")
End Select
GetUser = result
End Function
Private Sub Command363_Click()
Call GetUser
MsgBox "Username: " & GetUser
End Sub
ありがとうございます! – whatwhatwhat
また、 'Select Case NamePart'は'ケース選択部 'でなければなりません。 –
@ Mat'sMug true、edited。 – Brad