我有一个功能,可以将时间打印成5个批次的excel。我有一个函数,该函数首先将时间存储在集合对象中,然后将其转换为数组,最后该函数将调用另一个函数以将数组填充为excel。
在我的功能下面,供您参考。
Public daytime_store As New Collection
Public daytime_tm As New Collection
Public daytime_store_cnt As New Collection
Option Explicit
Function n50_store_day()
Dim I_day As Date, Currtime_cutoff As Date, daytime_store_arr As Variant, daytime_tm_arr As Variant, lx As Integer, ly As Integer
I_day = Format(Now(), "hh:mm:ss")
daytime_store.Add I_day
If daytime_store.Count = 5 Then
daytime_store_cnt.Add 5
ly = daytime_store_cnt.Count
If ly = 1 Then lx = 1
If ly > 1 Then lx = ((ly - 1) * 5) + 1
daytime_store_arr = CollectionToArray(daytime_store)
Set daytime_store = New Collection
Call varitoxl(daytime_store_arr, lx)
End If
End Function
如果我从F5运行该功能,但如果从电子表格中调用时显示错误的数据类型错误,则此方法可以正常工作。任何人都可以对此进行指导。
下面还有varitoxl的功能:
Function varitoxl(dlr As Variant, yz As Integer) As Variant
Dim strFilename As String: strFilename = "C:\Users\Acer\Desktop\n50imp\book1.xlsx"
Dim wb As Workbook
Set wb = Workbooks.Open(Filename:=strFilename)
Dim ws As Worksheet
Set ws = wb.Worksheets("sheet1")
Debug.Print 1
ws.Cells(yz, 1).Resize(5, 1) = dlr
Debug.Print 2
ActiveWorkbook.Close SaveChanges:=True
End Function