我有一个代码可以基于模板创建多个文件。模板文件包含编码验证。但是,在创建文件时,我尝试运行已为其编写验证代码的宏,但它会引发错误,提示“应用程序定义或对象定义的错误”。
使用模板创建多个文件的代码
Set wb = Workbooks.Add(strTemplate)
LastRowUV = sht1.Range("F" & Rows.Count).End(xlUp).Row
'MsgBox LastRowUV
Application.DisplayAlerts = False
For i = 2 To LastRowUV
ThisFile = sht1.Range("F" & i).Value
wb.SaveAs Filename:="\\lonfi0003.eur.xlPRithwik\Test\QB_" & ThisFile & ".xlsm", FileFormat:=52
Next i
数据验证代码
For i = 2 To LastRow1 + 1
With sht.Range("A" & i).Validation
.delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=DropDown!A2:A" & LastRowAT
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = "Value not present in drop down."
.ShowInput = True
.ShowError = True
End With
Next i