ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[Âà¶K] §»运¦æ¦Zªº«ìÎ`问题

[Âà¶K] §»运¦æ¦Zªº«ìÎ`问题

«Ü¤[¥H«e¦bºë­^©Î¨ä¥L¤Hªººô­¶¬Ý¹L.ÁöµM¤£¯à«ì´_©Ò¦³ªºªF¦è.¦ý¦Ü¤Ö¤]¬O­Ó·Qªk
³o«h¬Oexcelpxªº¤å³¹
§@ªÌ:¦Ñ½kÒ\?

§»运¦æ¦Zªº«ìÎ`问题


¥ÎVBA¥i¥H«ìÎ`¡A¦ý¤£¯à³q过Excel内¸mªº¥\¯à¦Û动实现¡C±z¥i¥H¨Ï¥ÎVBA¥N码记录¤U运¦æ§»µ{§Ç«e单¤¸®æ©Î单¤¸®æ区°ì­ì¥ýªº内®e¡A¦b¡§ºM销¡¨©R¥O¤¤调¥Î¥H«ìÎ`µ{§Ç运¦æ«eªº状态¡C
±z¥i¥H¨Ï¥ÎApplication对¶HªºOnUndo¤èªk§@为§»µ{§Ç结§ô«eªº³Ì¦Z¤@个¥N码¡A该¤èªk¤¹许±z«ü©w¥X现¦b¡§ºM销¡¨µæ单项¤¤ªº¤å¥»¥H¤Î点击该¤å¥»¦Z©Ò运¦æªº过µ{¡C¦p¤U­±ªº¥N码©Ò¥Ü¡G
Application.Onundo ¡§ºM销³Ì¦Z¤@个§»¡¨¡A¡¨«ìÎ`§»µ{§Ç¡¨
为说©ú¤W­z¤èªk¡A¤U­±¦C¥X¤F¤@个§¹¾ãªº¥Ü¨Ò¡C¥Ü¨Òªº§¹¾ã¥N码¥H¤Î¥N码说©ú¦p¤U¡G
¡¥**************************************************
Type RangeCellInfo '¦Û©w义类«¬¦s储§»运¦æ©Ò§@¥Xªº§ï变
    CellContent As Variant
    CellAddress As String
End TypePublic OrgWB As Workbook
Public OrgWS As Worksheet
Public OrgCells() As RangeCellInfo
¡¥**************************************************
Sub EditRange()
  ' ¦b©Ò¦³³Q选¨úªº单¤¸®æ¤¤´¡¤JX
  Dim i As Integer, cl As Range
  If TypeName(Selection) <> "Range" Then Exit Sub
  Application.ScreenUpdating = False
  ReDim OrgCells(Selection.Count)
  Set OrgWB = ActiveWorkbook
  Set OrgWS = ActiveSheet
  i = 1
  ¡¥记录¤U§»µ{§Ç对¤u§@ªí§@¥X§ï变«eªº状态
  For Each cl In Selection
    OrgCells(i).CellContent = cl.Formula
    OrgCells(i).CellAddress = cl.Address
    i = i + 1
  Next cl
  ¡¥¦b©Ò选单¤¸®æ¤¤¶ñ¤¹X
  Selection.Formula = "X"
  ¡¥«ü©w¦b¡§ºM销¡¨µæ单项¤¤ªº¤å¦r¤Î选择该©R¥O时©Ò执¦æªº§»µ{§Ç
  Application.OnUndo "ºM销³Ì¦Z运¦æªº§»过µ{¾Þ§@", "UndoEditRange"
End Sub
¡¥**************************************************
¡¥«ìÎ`¤u§@ªí­ì¥ýªº状态
Sub UndoEditRange()
  Dim i As Integer
  Application.ScreenUpdating = False
  On Error GoTo NoWBorWS
  OrgWB.Activate
  OrgWS.Activate
  On Error GoTo 0
  '«ìÎ`§»运¦æ©Ò§@ªº§ï变
  For i = 1 To UBound(OrgCells)
      Range(OrgCells(i).CellAddress).Formula = OrgCells(i).CellContent
  Next i
  Set OrgWB = Nothing
  Set OrgWS = Nothing
  Erase OrgCells
NoWBorWS:
End Sub

        ÀR«ä¦Û¦b : ¤@¥y·Å·xªº¸Ü¡A´N¹³©¹§O¤H¨­¤WÅx­»¤ô¡A¦Û¤v·|ªg¨ì¨â¤Tºw¡C
ªð¦^¦Cªí ¤W¤@¥DÃD