此代码一直有效,现在它给了我
运行时错误'1004'
此名称的语法不正确。
我认为在脚本运行后,我需要删除此保存的名称,但是,我不知道该怎么做。
如果在调试错误后我在with语句的开头启动了代码,那么它就起作用了。
ActiveWorkbook.Names.Add Name:="MyList1", RefersTo:="=FlexInfo[Card Holder]"
'RefersTo:="=TableName[ColumnHeader]"
With Range("CardHold").Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=MyList1" '<Errors here
.ShowError = False
End With
答案 0 :(得分:0)
看上去就像
On Error Resume Next
ActiveWorkbook.Names("MyList1").Delete
ActiveWorkbook.Names("FlexInfo[Card Holder]").Name = "FlexInfo[CardHolder]"
On Error GoTo 0
ActiveWorkbook.Names.Add Name:="MyList1", RefersTo:="=FlexInfo[CardHolder]"
'RefersTo:="=TableName[ColumnHeader]"
With Range("CardHold").Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=MyList1" '<Errors here
.ShowError = False
End With