다음 문서는 다음을 사용하여 캘린더를 표시하고 조사하는 방법을 보여줍니다. 쥐. 
* 실제에서는 데이터베이스에 의미있는 일기 항목을 읽고 쓰는 양식을 엽니 다. 이 연습에서는 단순히 오른쪽 클릭의 메커니즘을 보여주고 워크 시트 자체에서 세부 정보를 찾습니다.
시작하기 전에 작업 모델을 찾을 수있는 스프레드 시트에 대한 몇 마디 설명 여기에서 확인하세요.
과정
그리드 내의 셀을 클릭하면 해당 셀이 강조 표시되고 값이 변경됩니다. 클릭하고 드래그하면 범위가 강조 표시되고 값이 변경됩니다. 셀이 채워지면 지워지고, 그렇지 않으면 "*"로 채워집니다.
대조적으로 right_click은 선택한 셀의 정보 요청입니다.
기본적으로 여러 모듈과 함께 두 개의 이벤트가 사용됩니다.
- 워크시트_선택변경 셀이 선택 될 때 호출됩니다.
- 워크시트_BeforeRightClick 오른쪽 마우스 버튼으로 호출됩니다.
문제
셀을 마우스 오른쪽 버튼으로 클릭하면 선택이 구성되어 선택변경. 이벤트가 진행되도록해야하며, 제어권을 오른쪽 클릭 전k 이벤트, 지워진 셀을 다시 채울 때. 그러나이 행동은 선택 변경됨 다시 한 번 지우기를 중지해야합니다.
blnLoading이라는 부울 플래그로이를 수행합니다.
그 사건들
워크 시트 뒤의 코드 창에 다음을 입력합니다 (즉, 모듈이 아님).
Option Explicit
Dim blnLoading As Boolean
Dim sPhase As String
Dim currCellValue As String
Dim dDate As Date
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Row > 14 And ActiveCell.Row < 25 Then
If ActiveCell.Column > 4 And ActiveCell.Column < 47 Then 'selection is valid
On Error Resume Next
currCellValue = Target.Value 'get the target value from (ByVal Target As Range)
If blnLoading = True Then 'a value of True will force an exit from this event
blnLoading = False
Exit Sub
End If
sPhase = Cells(ActiveCell.Row, 1)
If sPhase = "" Then Exit Sub
If ActiveCell = "*" Then 'if the cell is populated, clear the selected range
Call ClearRange
Call UnblockCalendar
Else
Call PopulateRange
End If
Call RedrawCells
Range("A1").Select 'revive the SelectionChange event by changing selection.
Exit Sub
End If
End If
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If currCellValue = "*" Then 'picked up by the previous event BEFORE it cleared it;
'This means this is a valid diary entry with detail.
blnLoading = True 'this will prevent the SelectionChange event (above) from running.
Target.Select
'currCell = Target.Address
'Range(currCell).Select
Target.Value = "*" 're-instate the value of the cell, since SelectionChange has cleared it
Call PopulateRange
dDate = Cells(13, ActiveCell.Column)
sPhase = Cells(ActiveCell.Row, 1)
MsgBox dDate & " - " & sPhase
Cancel = True 'suppress Excel’s standard right_click menus
End If
Range("A1").Select
blnLoading = False
End Sub
이것은 두 개의 이벤트를 처리합니다.
참조 코드
다음, 채우기 및 채우기 범위를 코드에 추가합니다.
Sub ClearRange() Selection.FormulaR1C1 = "" With Selection.Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With End Sub Sub PopulateRange() Selection.FormulaR1C1 = "*" With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.799981688894314 .PatternTintAndShade = 0 End With End Sub
격자 선 유지 관리
응용 프로그램에 모듈을 삽입합니다. 그리드 모양을 유지하기 위해 다음 코드를 추가합니다. 이것은 매크로 레코더, 중복 및 모든 것에서 복사되었습니다.
Option Explicit Sub UnblockCalendar() Selection.FormulaR1C1 = "" With Selection Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone Selection.Borders(xlEdgeBottom).LineStyle = xlNone Selection.Borders(xlEdgeRight).LineStyle = xlNone Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone End With End Sub Sub RedrawCells() Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With End Sub
재난으로부터 보호
엑셀 개발을 많이 해본 사람이라면 누구나 복잡한 xlsm 스프레드시트가 때때로 오류를 일으켜 열려 있는 문서가 손상되는 것을 경험해 봤을 것입니다. 생각보다 많은 경우, 손상된 통합 문서는 엑셀의 복구 기능으로 복구할 수 없습니다. 백업이 없다면 작업 내용이 모두 손실됩니다. 이러한 문제는 오류 발생 시 복구를 수행하도록 설계된 도구를 사용하면 예방할 수 있습니다. Excel 수정.
저자 소개 :
Felix Hooker는 데이터 복구 전문가입니다. DataNumen, Inc.는 다음과 같은 데이터 복구 기술 분야의 세계적 리더입니다. rar 수리 및 SQL 복구 소프트웨어 제품. 자세한 내용은 WWW.datanumen.COM
