Ipinapakita ng sumusunod na artikulo kung paano markahan at tanungin ang isang kalendaryo sa mouse 
* Sa totoong mundo, magbubukas kami ng isang form upang mabasa at isulat ang mga makahulugang talaarawan sa isang database. Ang ehersisyo na ito ay simpleng ipinapakita ang mekanika ng right_clicking, at nahahanap ang mga detalye mula sa worksheet mismo.
Bago kami magsimula, ang ilang mga salita ng paliwanag tungkol sa spreadsheet, isang modelo ng pagtatrabaho na matatagpuan dito.
Ang Proseso
Ang pag-click sa isang cell sa loob ng grid ay i-highlight ang cell na iyon at babaguhin ang halaga nito. I-highlight ng pag-click at pag-drag ang isang saklaw at babaguhin ang mga halaga nito. Kung ang isang cell ay na-populate, ito ay malilinaw, kung hindi man ay mapupuno ito, sa kasong ito ng isang "*".
Ang isang right_click sa pamamagitan ng kaibahan ay isang kahilingan para sa impormasyon mula sa napiling cell.
Mayroong mahalagang dalawang kaganapan na ginamit, kasama ang maraming mga module.
- Worksheet_SelectionChange na kung saan ay napili kapag ang isang cell o cells ay napili.
- Worksheet_BeforeRightClick na tinawag ng kanang pindutan ng mouse.
Ang problema
Ang pag-rightclick ng isang cell ay bumubuo rin ng isang pagpipilian, nagpapalitaw Pagbabago ng Pinili. Papayagan natin ang kaganapang iyon na magpatakbo ng kurso nito, i-clear ang cell na napili bago ito sumuko sa kontrol sa BeforeRightClick kaganapan, kapag muli nating ilalagay ang na-clear na cell. Ngunit ang pagkilos na ito ay magti-trigger ng Napili ang Seleksyon kaganapan muli, na dapat ihinto mula sa pag-clear nito muli.
Gagawin namin ito sa isang flag ng boolean na tinatawag na blnLoading.
Ang mga kaganapan
Ipasok ang sumusunod sa code window sa likod ng worksheet (ibig sabihin wala sa isang module).
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
Pinangangalagaan nito ang dalawang Kaganapan.
Sumangguni sa Code
Ikabit ang mga sumusunod, pumupuno at sumisira na mga saklaw, sa code:
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
Pagpapanatili ng Gridlines
Magpasok ng isang module sa application. Idagdag ang sumusunod na code para sa pagpapanatili ng hitsura ng grid. Kinopya ito mula sa recorder ng macro, mga kalabisan at lahat.
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
Pag-iingat laban sa sakuna
Alam ng sinumang gumagawa ng maraming pag-develop ng Excel na ang mga kumplikadong xlsm spreadsheet ay maaaring mag-crash paminsan-minsan, na nagdudulot ng pagkasira sa binuksang dokumento. Sa mas maraming pagkakataon kaysa sa inaasahan, ang nasirang workbook ay hindi mababawi ng mga recovery routine ng Excel. Kung walang mga backup, mawawala ang gawaing nagawa. Maiiwasan ito gamit ang mga tool na idinisenyo upang maisagawa ang mga... Pag-ayos ng Excel.
Panimula ng May-akda:
Si Felix Hooker ay isang dalubhasa sa pagbawi ng data sa DataNumen, Inc., na pinuno ng mundo sa mga teknolohiya sa pagbawi ng data, kasama ang pagkukumpuni ng rar at mga produkto ng software sa pag-recover ng sql. Para sa karagdagang impormasyon pagbisita www.datanumen. Sa
