[英]Compile Error: Argument Not Optional when Argument is supplied
Hi I keep getting a Compile error: Argument not optional in my VBA excel code when I have supplied arguments function used.嗨,我一直收到编译错误:当我提供了使用的参数函数时,我的 VBA excel 代码中的参数不是可选的。 The Main purpose of the function is to record values from one workbook and save into another as an audit log.该函数的主要目的是记录一个工作簿中的值并将其作为审计日志保存到另一个工作簿中。 However I get the error above and can't find a solution because it looks like I have supplied arguments to every function component that requires it.但是我得到了上面的错误并且找不到解决方案,因为看起来我已经为每个需要它的函数组件提供了参数。
Public Sub LogResults ()
Call RecordAudit(CreateCollection)
End Sub
Public Function CreateCollection() As Collection
Dim colProspectValues As New Collection
Dim ManRateCredibility As Double
ManRateCredibility = 0
ManRateCredibility = CDbl(1 - worksheets("whorksheetname").Range("A1").Value)
colProspectValues.Add Worksheets("worksheetname").Range("A2").Value
colProspectValues.Add Worksheets("worksheetname").Range("A3").Value
colProspectValues.Add Worksheets("worksheetname").Range("A4").Value
colProspectValues.Add Worksheets("worksheetname").Range("A5").Value
colProspectValues.Add Worksheets("worksheetname").Range("A6").Value
colProspectValues.Add ManRateCredibility
Set CreateCollection = colProspectValues
End Function
Public Sub RecordAudit(ByRef aCollection As Collection)
Dim tempCollection as Collection
Dim i As Integer
Dim wbMaster As Workbook
Dim wbLocal As Workbook
Dim MasterNextRow As Long
Dim AuditLogPath As String
Application.ScreenUpdating = False
Set tempCollection = aCollection
AuditLogPath = "H:\FolderB\Model\ProspectAudit.xlsx"
Set wbMaster = Workbooks(AuditLogPath)
MasterNextRow = wbMaster.Worksheets("AuditLog").Range("B" & wbMaster.Worksheets("AuditLog").Rows.count).End(xlUp).Offset(1).Row
For i = 1 to tempCollection.count
wbMaster.Worksheets("AuditLog").Cells(MasterNextRow, i).Value =
tempCollection.Item(i)
Next i
End Sub
Found out what it was.发现它是什么。 I had not fully defined the function required when setting the workbook path using Workbooks.Open(AuditLogPath) instead of Workbooks(AuditLogPath)我没有完全定义使用 Workbooks.Open(AuditLogPath) 而不是 Workbooks(AuditLogPath) 设置工作簿路径时所需的功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.