我有以下代码用于处理我的电子表格 VBA 宏上的用户表单:
Option Explicit
Public saved_vocab As String
Public saved_num As String
Public saved_def As String
Public saved_ex As String
Private Sub Save_Click()
Dim low As Integer
Dim high As Integer
Dim selected As Integer
low = 1
high = Cells(1, 1).End(xlDown).Row
Range(Cells(low, 1), Cells(high, 1)).Find(what:=vocab.Text, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
selected = ActiveCell.Row
saved_vocb = Cells(selected, 1).Text
saved_num = Cells(selected, 2).Text
saved_def = Cells(selected, 3).Text
saved_ex = Cells(selected, 4).Text
Cells(selected, 1) = vocab.Text
Cells(selected, 2) = num.Text
Cells(selected, 3) = definition.Text
Cells(selected, 4) = example.Text
End Sub
Private Sub undo_Click()
Cells(selected, 1) = saved_vocab
Cells(selected, 2) = saved_num
Cells(selected, 3) = saved_def
Cells(selected, 4) = saved_ex
End Sub
我想要做的是将信息正确保存在saved_??? 字符串值,以便在我决定单击“撤消”按钮执行第二个函数时可以正确访问它。但是,当我执行第二个函数时,之前保存在saved_中的信息????变量消失了,也许是我自己处理变量范围不正确的原因。完成我想做的最简单的方法是什么?提前感谢您的建议。