我试图编写一个脚本,列出上次保存每个六个输入模板的最后时间/日期。前4个似乎工作正常,但当我到达第5& 6日(TemplateWB1& TemplateWB2),我收到以下错误: "编译错误:ByRef参数类型不匹配"
我无法弄清楚为什么其中一些有效,但其他人没有......?我已多次检查并重新检查文件路径,并且它们是正确的。
Sub RefreshSaveDateTimes()
Dim DateWBpath As String
Dim DistWBpath As String
Dim prdWBpath As String
Dim sparkUPCitemWBpath As String
Dim myDate As Date
Dim menuMenuWS As Worksheet
Dim TemplateWB1, TemplateWB2 As String
Set menuMenuWS = ActiveWorkbook.Worksheets("Menu")
DateWBpath = "P:\CPW Planning Tool\DataSources\DateTable.xlsx"
DistWBpath = "P:\CPW Planning Tool\Input Templates\Confections\Confections Distribution Inputs.xlsm"
prdWBpath = "P:\CPW Planning Tool\Input Templates\Confections\Confections PRD Inputs.xlsm"
sparkUPCitemWBpath = "P:\CPW Planning Tool\Input Templates\Confections\Confections Spark UPC Item Table.xlsx"
TemplateWB1 = "P:\CPW Planning Tool\Input Templates\Confections\Forecast Template 1 - Confy.xlsm"
TemplateWB2 = "P:\CPW Planning Tool\Input Templates\Confections\Forecast Template 2 - Confy.xlsm"
myDate = LastSaved(DateWBpath)
menuMenuWS.Cells(2, 3).Select
ActiveCell.Value = myDate
myDate = LastSaved(sparkUPCitemWBpath)
menuMenuWS.Cells(3, 3).Select
ActiveCell.Value = myDate
myDate = LastSaved(prdWBpath)
menuMenuWS.Cells(4, 3).Select
ActiveCell.Value = myDate
myDate = LastSaved(DistWBpath)
menuMenuWS.Cells(5, 3).Select
ActiveCell.Value = myDate
myDate = LastSaved(TemplateWB1)
menuMenuWS.Cells(6, 3).Select
ActiveCell.Value = myDate
myDate = LastSaved(TemplateWB2)
menuMenuWS.Cells(7, 3).Select
ActiveCell.Value = myDate
End Sub
答案 0 :(得分:1)
只是因为当你写这篇文章时:
Dim TemplateWB1, TemplateWB2 As String
TemplateWB1
实际上是Variant
,而不是String
。您必须为每个变量指定类型:
Dim TemplateWB1 As String, TemplateWB2 As String