【发布时间】:2015-04-20 07:15:06
【问题描述】:
我正在尝试创建一个包含一堆 o 常量字符串的文档。
我已经在这样的模块中声明了 Public:
Public Abc As String
在“ThisWorkbook”中,我运行以下代码来初始化 de 变量
Private Sub Workbook_Open()
Abc = "C5"
End Sub
我有 Buttons 编码来改变一些值,比如:
If Range(Abc) = "" Then
Range(Abc) = 1
Else
Range(Abc) = Range(Abc) + 1
End If
当我使用此代码运行按钮时:
Sub BotaoNovoDia()
i = 3
While i <= 33
If Cells(i, 11) = "" Then
Cells(i, 11) = Range(Apresentacao)
Cells(i, 12) = Range(Aceitacao)
Cells(i, 13) = Range(Aceitou)
Cells(i, 31) = Range("D41")
Cells(i, 11).Interior.Color = Range(Apresentacao).Interior.Color
Cells(i, 12).Interior.Color = Range(Aceitacao).Interior.Color
If Range("K34") < 0.65 Then
Range("K34").Interior.Color = vbRed
Else
Range("K34").Interior.Color = vbGreen
End If
If Range("L34") < 0.45 Then
Range("L34").Interior.Color = vbRed
Else
Range("L34").Interior.Color = vbGreen
End If
Range(Aceitou) = 0
Range(Rejeitou) = 0
Range(NaoApres) = 0
End
Else
i = i + 1
End If
Wend
End Sub
我尝试再次运行第一个按钮,但出现错误提示:“运行时错误'1004':对象'_Global'的方法'范围'失败” 调试按钮将我带到尝试访问公共变量值的第一行。我可以做些什么来维护公共变量中的值?
【问题讨论】:
-
您可以在工作簿中使用
Name来存储值,这甚至会在运行时持续存在。