방법: 셀에 현재 사용자의 로그온 ID 표시

현재 사용자를 나타내는 WindowsIdentity 개체의 GetCurrent 메서드를 사용하여 현재 사용자의 로그온 ID를 읽을 수 있습니다. 그런 다음 Microsoft Office Excel 워크시트의 명명된 범위에 사용자의 로그온 ID를 표시할 수 있습니다.

적용 대상: 이 항목의 정보는 Excel 2007 및 Excel 2010의 문서 수준 프로젝트 및 응용 프로그램 수준 프로젝트에 적용됩니다. 자세한 내용은 Office 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

셀에 텍스트를 표시하려면 NamedRange 컨트롤이나 네이티브 Excel 범위 개체를 사용합니다.

NamedRange 컨트롤 사용

이 예제는 문서 수준 사용자 지정을 위한 것입니다. 다음 코드는 ThisWorkbook 클래스가 아닌 시트 클래스에 배치해야 합니다.

현재 사용자의 로그온 ID를 명명된 범위에 표시하려면

  1. 사용자의 로그온 ID를 가져옵니다.

    Dim user As System.Security.Principal.WindowsIdentity
    user = System.Security.Principal.WindowsIdentity.GetCurrent()
    
    System.Security.Principal.WindowsIdentity user;
    user = System.Security.Principal.WindowsIdentity.GetCurrent();
    
  2. userID라는 NamedRange 컨트롤을 만들고 사용자의 로그인 ID를 표시합니다.

    Dim userID As Microsoft.Office.Tools.Excel.NamedRange
    userID = Me.Controls.AddNamedRange(Me.Range("A1"), "userID")
    
    userID.Value2 = user.Name
    
    Microsoft.Office.Tools.Excel.NamedRange userID;
    userID = this.Controls.AddNamedRange(this.Range["A1", missing], "userID");
    
    userID.Value2 = user.Name;
    

네이티브 Excel 범위 사용

현재 사용자의 로그온 ID를 네이티브 Excel 범위에 표시하려면

  1. 사용자의 로그온 ID를 가져옵니다.

    Dim user As System.Security.Principal.WindowsIdentity
    user = System.Security.Principal.WindowsIdentity.GetCurrent()
    
    System.Security.Principal.WindowsIdentity user;
    user = System.Security.Principal.WindowsIdentity.GetCurrent();
    
  2. userID라는 Range 컨트롤을 만들고 사용자의 로그인 ID를 표시합니다.

    Dim userID As Excel.Range = Me.Application.Range("A1")
    
    userID.Value2 = user.Name
    
    Excel.Range userID = this.Application.get_Range("A1", missing);
    
    userID.Value2 = user.Name;
    

강력한 프로그래밍

다음 조건에서 예외가 발생합니다.

참고 항목

작업

방법: 코드에서 워크시트 범위 참조

방법: WindowsPrincipal 개체 만들기

개념

셀 작업

Office 솔루션의 선택적 매개 변수