编译错误:当我从其他macros调用macros时,参数不是可选错误

我有一个button,按下时会调用一些macros来完成。 我所有的macros都运行正常,“AddDropDown”macros的例外。 它不断给我一个错误,说“编译错误:参数不可选(错误449)”。

这些运行正常,如果我手动只select他们,然后按运行。

帮助页面显示“参数的数量和types必须与预期的一致。 此错误具有以下原因和解决scheme:•参数个数不正确。 提供所有必要的参数。 例如,Left函数需要两个参数; 第一个表示正在操作的string,第二个表示要从string左侧返回的字符数。 因为这两个参数都不是可选的,所以都必须提供。 •省略的参数不是可选的。 如果在过程声明中将参数声明为可选,则只能从对用户定义过程的调用中省略参数。 要么在调用中提供参数,要么在定义中声明参数Optional。

我的代码是这样的:

Private Sub Button_Click() Macro1 Macro2 AddDropDowns AddDropDown Macro3 End Sub 

而给出错误的macros是下面的那个:

 Sub AddDropDowns() Dim cell As Range Dim iDropDown As Long With Worksheets("SourceSheet") For Each cell In .Range("B13", .Cells(13, .Columns.Count).End(xlToLeft)).SpecialCells(XlCellType.xlCellTypeConstants) AddDropDownEnroll Worksheets("DropDownsSheet"), iDropDown, cell.Offset(-1).Value, "='" & .Name & "'!" & cell.Resize(WorksheetFunction.CountA(cell.EntireColumn) - 1).Address Next cell End With End Sub Sub AddDropDown(sht As Worksheet, dropDownCounter As Long, header As String, validationFormula As String) With sht.Range("A1").Offset(, dropDownCounter) '<--| reference passed sheet row 1 passed column .Cells(1, 1) = header '<--| write header With .Cells(2, 1).Validation '<--| reference 'Validation' property of cell 1 row below currently referenced one .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=validationFormula .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With End With dropDownCounter = dropDownCounter + 1 End Sub 

Sub Button_Click() ,更改:

 Private Sub Button_Click() Macro1 Macro2 AddDropDowns AddDropDown Macro3 End Sub 

成:

 Private Sub Button_Click() Macro1 Macro2 AddDropDowns Macro3 End Sub 

AddDropDowns() ,更改:

 AddDropDownEnroll Worksheets("DropDownsSheet"), iDropDown, cell.Offset(-1).Value, "='" & .Name & "'!" & cell.Resize(WorksheetFunction.CountA(cell.EntireColumn) - 1).Address 

成:

 AddDropDown Worksheets("DropDownsSheet"), iDropDown, cell.Offset(-1).Value, "='" & .Name & "'!" & cell.Resize(WorksheetFunction.CountA(cell.EntireColumn) - 1).Address