我知道我可能正在尝试做一些不正常的事情。我需要从 Controls FormatConditions 集合中保存(并删除)所有 FormatCondition 对象。然后稍后我需要重新创建/重新将那些相同的 FormatCondition 对象重新应用回同一个控件。
似乎我可以成功复制它们,但是当我尝试从我自己的 Collection 对象中重新应用那些相同的 FormatCondition 对象时出现错误。我怀疑这里发生的事情是我实际上并没有像我想的那样在我的 SaveAndDelete 例程中复制对象。如果是这种情况,我如何才能真正克隆这些对象,以便在我运行 f.Delete 后它们仍然存在?
Private SavedFC As New Collection
Private Sub SaveAndDeleteFormatConditions(c as Control)
Dim f As FormatCondition
For Each f In c.FormatConditions
SavedFC.Add f
f.Delete
Next
End Sub
Private Sub RecreateFormatConditions(c as control)
Dim i As Integer
i = 1
If SavedFC.Count > 0 Then
Dim f1 As FormatCondition, f2 As FormatCondition
For Each f1 In SavedFC
'Error 2467 occurs here: The expression you entered refers to an object that is closed or doesn't exist
Set f2 = c.FormatConditions.Add(f1.Type, f1.Operator, f1.Expression1, f1.Expression2)
With f2
.BackColor = f1.BackColor
.FontBold = f1.FontBold
.FontItalic = f1.FontItalic
.FontUnderline = f1.FontUnderline
.ForeColor = f1.ForeColor
End With
SavedFC(i).Delete
i = i + 1
Next
End If
End Sub