티스토리 뷰

 

MS Office Word 에서 Print(인쇄)와 Save(저장), Save As(다른이름 저장)을 제어하는 VBA 코드입니다.

 

 

 

[사용자 정의 폼]

 

Private Sub Document_Close()
    ConfRegister_Event_Handler_Close
End Sub

 

Private Sub Document_Open()

    '
    Dim strFolder As String
   

    ConfRegister_Event_Handler_Init
    strFolder = Dir("C:\특정디렉토리", vbDirectory)
    If Len(strFolder) < 1 Then
       
        Application.Quit SaveChanges:=wdDoNotSaveChanges
    End If
   
End Sub

 

 

[모듈]


Dim YCConfidential As New YConfidentialClassModule

 

Sub ConfRegister_Event_Handler_Init()
 Set YCConfidential.appWord = Word.Application
End Sub

 

Sub ConfRegister_Event_Handler_Close()
 Set YCConfidential.appWord = Nothing
End Sub

 

 

[클래스 모듈]

Public WithEvents appWord As Word.Application
 
Private Sub appWord_DocumentBeforePrint _
 (ByVal Doc As Document, _
 Cancel As Boolean)

 
 Dim intResponse As Integer
 
 intResponse = MsgBox("이문서는 [대외비]입니다." & Chr(10) _
 & Chr(10) & Chr(10) & "인쇄, 복사는 금지되어 있으며, 내용 참조만 가능합니다.", _
 vbOKOnly + vbInformation, " YcITeam - [대외비]입니다.")
 
 Cancel = True
 
End Sub

 

Private Sub appWord_DocumentBeforeSave _
 (ByVal Doc As Document, _
 SaveAsUI As Boolean, _
 Cancel As Boolean)

 

 Dim intResponse, intCode As Integer
 Dim strDocName As String
     
 On Error Resume Next
 
 strDocName = ActiveDocument.Name
 If InStr(1, strDocName, "대외비") > 0 Then
 
    intResponse = MsgBox("이문서는 [대외비]입니다." & Chr(10) _
            & Chr(10) & Chr(10) & "다른이름 저장이 금지되어 있으며, 내용 참조만 가능합니다.", OKOnly + vbInformation, " YcITeam - [대외비]입니다.")
 
    intCode = InputBox("저장 코드값을 입력하세요. 숫자로 입력바랍니다.")
 
 
    If OnError Or (Not IsNumeric(intCode)) Then
        intCode = 0
    End If
 
    If intCode = 5344 Then
         SaveAsUI = True
        Cancel = False
    Else
         SaveAsUI = False
        Cancel = True
    End If
 End If
End Sub

 

 

 

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함