0
當我嘗試運行一個子(下)時,我得到編譯錯誤:參數不是可選的,在行Set wb = getDensityTemplate()
。任何人都可以向我解釋這個嗎?感謝Thomas Inzina爲我提供此代碼。「參數不可選」錯誤運行時
Public Sub MultipleParts()
Dim vFiles As Variant, FileFullName As Variant
Dim NextRow As Range, wb As Workbook
Dim CalculationMode As XlCalculation
CalculationMode = ToggleEvents(False, xlCalculationManual)
vFiles = getFileList("C:\Users\OneDrive-CoorsTek\temp", "*.xls*")
If UBound(vFiles) = -1 Then
MsgBox "No files found", vbInformation, ""
Exit Sub
End If
Set wb = getDensityTemplate()
For Each FileFullName In vFiles
With wb.Worksheets(1)
'Add Header
.Range("A1:H1").Value = Array("FileName", "Description", "WaterTemp(C)", "WaterDensity(g/cc)", "PartID", "DryMass(g)", "SuspendedMass(g)", "Density(g/cc)")
'Target the next empty row
Set NextRow = .Range("A" & .Rows.Count).End(xlUp).Offset(1)
AddBatchCard CStr(FileFullName), NextRow
End With
Next
ToggleEvents True, CalculationMode
End Sub
還顯示了getDensityTemplate
子。
Private Function getDensityTemplate(FilePath As String) As Workbook
Dim SheetsInNewWorkbook As Integer
Dim wb As Workbook
SheetsInNewWorkbook = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Set wb = Workbooks.Add(xlWBATWorksheet)
wb.Worksheets(1).Name = "Density"
wb.SaveAs FileName:=FilePath & "DensitySummary" & Format(Now, "yyyy_mm_dd_hh.mm")
Set getDensityTemplate = wb
端功能
看起來像它缺少變量...你可以更新列出的getDensityTemplate子你的問題 – ShanayL
你可以發佈getDensityTemplate的代碼嗎? – jcarroll
根據這個頁面,你似乎需要爲它的文件路徑傳遞一個字符串。 https://stackoverflow.com/questions/46718110/create-separate-row-for-each-item-when-merging-multiple-workbooks – newacc2240