방법: 통합 문서 암호 설정 및 지우기
업데이트: 2008년 7월
적용 대상 |
---|
이 항목의 정보는 지정된 Visual Studio Tools for Office 프로젝트 및 Microsoft Office 버전에만 적용됩니다. 프로젝트 형식
Microsoft Office 버전
자세한 내용은 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오. |
암호를 만들어 통합 문서에 대한 액세스를 제한할 수 있습니다. 다음 예제에서는 통합 문서의 암호를 설정합니다. 암호를 지우려면 암호를 빈 문자열로 설정합니다.
문서 수준 사용자 지정에서 암호 설정
암호를 설정하려면
ThisWorkbook의 암호 속성을 사용자가 입력한 문자열로 설정합니다.
Private Sub SetPassword() Dim password As String Dim confirmPassword As String password = Me.Application.InputBox("Enter the new password:").ToString() confirmPassword = Me.Application.InputBox("Confirm the password:").ToString() If password <> confirmPassword Then MessageBox.Show("The passwords you typed do not match.") Globals.ThisWorkbook.Password = "" Else Globals.ThisWorkbook.Password = password End If End Sub
private void SetPassword() { string password = this.Application.InputBox("Enter the new password:", missing, missing, missing, missing, missing, missing, missing).ToString(); string confirmPassword = this.Application.InputBox("Confirm the password:", missing, missing, missing, missing, missing, missing, missing).ToString(); if (password != confirmPassword) { MessageBox.Show("The passwords you typed do not match."); Globals.ThisWorkbook.Password = ""; } else { Globals.ThisWorkbook.Password = password; } }
응용 프로그램 수준 추가 기능에서 암호 설정
활성 통합 문서의 암호를 설정하려면
Microsoft.Office.Interop.Excel._Workbook 클래스의 Password 속성을 사용자가 입력한 문자열로 설정합니다. 이 예제를 사용하려면 프로젝트의 ThisAddIn 클래스에서 이 코드를 실행하십시오.
Private Sub SetPassword() Dim password As String Dim confirmPassword As String password = Me.Application.InputBox("Enter the new password:").ToString() confirmPassword = Me.Application.InputBox("Confirm the password:").ToString() If password <> confirmPassword Then System.Windows.Forms.MessageBox.Show("The passwords you typed do not match.") Me.Application.ActiveWorkbook.Password = "" Else Me.Application.ActiveWorkbook.Password = password End If End Sub
private void SetPassword() { string password = this.Application.InputBox("Enter the new password:", missing, missing, missing, missing, missing, missing, missing).ToString(); string confirmPassword = this.Application.InputBox("Confirm the password:", missing, missing, missing, missing, missing, missing, missing).ToString(); if (password != confirmPassword) { System.Windows.Forms.MessageBox.Show ("The passwords you typed do not match."); this.Application.ActiveWorkbook.Password = ""; } else { this.Application.ActiveWorkbook.Password = password; } }
참고 항목
작업
개념
Visual Studio Tools for Office 프로젝트의 개체에 전역 액세스
변경 기록
날짜 |
변경 내용 |
이유 |
---|---|---|
2008년 7월 |
응용 프로그램 수준 추가 기능에 사용할 수 있는 코드 예제가 추가되었습니다. |
고객 의견 |