我似乎已经成功创建了这个全局字符串变量,因为我可以在我尝试使用它的子目录中的MsgBox中打印它。
当前代码:
First Sub:
Option Explicit
Public storeName As String
Sub cleanupProdReq()
'takes storename as public variable
storeName = Cells(5, "C").Value
Next Sub:
Sub SelectActualUsedRange()
Dim w As Workbook
Set w = ActiveWorkbook
'opens requests workbook, names sheet today unles there is already one
Workbooks.Open ("C:\Users\***\Documents\***\***\Supply Chain\Requests")
Dim wsTest As Worksheet
Const strSheetName As String = storeName
当我运行它时,它突出显示最后一次出现的'storeName'并给出错误:“Constant Expression Required”。任何人都可以建议解决这个问题吗?
答案 0 :(得分:0)
for of
必须在编译时确定Const strSheetName As String = storeName
的值。
您将其分配给变量,该变量的值仅在运行时确定。
使用Const
代替Dim
来声明Const
,编译器会很高兴。