Share via


WorkbookBase.Saved 속성

통합 문서가 마지막으로 저장된 이후 변경된 내용이 없는지 여부를 나타내는 값을 가져오거나 설정합니다.

네임스페이스:  Microsoft.Office.Tools.Excel
어셈블리:  Microsoft.Office.Tools.Excel.v4.0.Utilities(Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

구문

‘선언
Public Property Saved As Boolean
    Get
    Set
public bool Saved { get; set; }

속성 값

형식: System.Boolean
통합 문서가 마지막으로 저장된 이후에 변경 내용이 없으면 true이고, 그렇지 않으면 false입니다.

설명

이전에 통합 문서를 저장한 적이 없으면 이 Path 속성은 빈 문자열("")을 반환합니다.

수정한 통합 문서를 저장하지 않고 닫거나 저장할 것인지 묻는 메시지 없이 닫으려면 이 속성을 true로 설정하면 됩니다.

예제

다음 코드 예제에서는 통합 문서가 마지막으로 저장된 이후 변경된 내용이 있는 경우 변경 내용을 저장할 것인지, 저장하지 않을 것인지, 닫기 작업을 취소할 것인지 묻는 BeforeClose 이벤트 처리기를 보여 줍니다. 사용자가 변경 내용을 저장하지 않으면 통합 문서의 Saved 속성이 true로 설정되어 Microsoft Office Excel에서 닫기 작업을 계속할 때 통합 문서를 저장할 것인지 묻지 않습니다. 사용자가 닫기 작업을 취소하면 WorkbookEvents_BeforeCloseEventHandler 이벤트 처리기의 Cancel 매개 변수가 true로 설정되어 Microsoft Office Excel에서 통합 문서를 닫지 않습니다.

이 예제는 문서 수준 사용자 지정을 위한 것입니다.

Sub ThisWorkbook_BeforeClose(ByRef Cancel As Boolean) _
    Handles Me.BeforeClose

    If Not Me.Saved Then
        Dim result As DialogResult = _
            MessageBox.Show("Do you want to save the " & _
            "changes you made to " & Me.Name & "?", _
            "Example", MessageBoxButtons.YesNoCancel)

        Select Case result
            Case DialogResult.Yes
                Me.Save()
            Case DialogResult.Cancel
                Cancel = True
                ' The following code ensures that the default Save File 
                ' dialog is not displayed.
            Case DialogResult.No
                Me.Saved = True
        End Select
    End If
End Sub
private void WorkbookBeforeClose()
{
    this.BeforeClose +=
        new Excel.WorkbookEvents_BeforeCloseEventHandler(
        ThisWorkbook_BeforeClose);
}

void ThisWorkbook_BeforeClose(ref bool Cancel)
{
    if (!this.Saved)
    {
        DialogResult result = MessageBox.Show("Do you want to save the " +
            "changes you made to " + this.Name + "?", "Example",
            MessageBoxButtons.YesNoCancel);

        switch (result)
        {
            case DialogResult.Yes:
                this.Save();
                break;

            case DialogResult.Cancel:
                Cancel = true;
                break;

            // The following code ensures that the default Save File 
            // dialog is not displayed.
            case DialogResult.No:
                this.Saved = true;
                break;
        }
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

WorkbookBase 클래스

Microsoft.Office.Tools.Excel 네임스페이스