0
我有兩個Excels作爲輸入。我從一個excel中取值,並將其作爲參數傳遞給其他應用過濾器的excel。一旦過濾器打開,我正在讀取列中的過濾值並嘗試匹配下面代碼中提到的條件。一切正常工作到這個地方。一旦我得到了特定的匹配,我必須將它寫回第一個Excel,但是我在這樣做時遇到了運行時錯誤。VBScript運行時錯誤
strPath = "C:\Users\PSingh\Desktop\CodeInventory.xlsx"
strPath1 = "C:\Users\PSingh\Desktop\MyScripts\Processes.xlsx"
Dim rows
Set objExcel1 = CreateObject("Excel.Application")
objExcel1.Visible = True
Set objExcel2 = CreateObject("Excel.Application")
objExcel2.Visible = True
Set objDict = CreateObject("Scripting.Dictionary")
objDict.CompareMode = vbTextCompare
Const xlUp = -4162
Const xlCellTypeVisible = 12
Dim a(), val
objExcel1.Workbooks.Open(strPath1)
With objExcel1.Activeworkbook.Sheets("Sheet1")
rowcount = .Range("A" & .Rows.Count).End(xlUp).Row
MsgBox rowcount
End With
Redim Preserve a(rowcount)
For i=1 To rowcount
a(i) = objExcel1.Activeworkbook.Sheets("Sheet1").Cells(i,1).Value
objDict(a(i)) = a(i)
'msgbox a(i)
Next
n = objDict.Items
objExcel2.Workbooks.Open(strPath)
For i=0 To UBound(n)
With objExcel2.Activeworkbook.Sheets("All")
.Range("A1").AutoFilter 19, "="&n(i)
'rows=.usedrange.columns(1).specialcells(xlCellTypeVisible)
For Each cl In objExcel2.Activeworkbook.Sheets("All").UsedRange.Columns(12).SpecialCells(xlCellTypeVisible)
If (InStr(cl, "Seq") <> 0 Or InStr(cl,"seq")) <> 0 Then
objExcel1.Activeworkbook.Sheets("Sheet1").Cells(i,2) = "Data" 'Not Working
Exit For
End If
Next
End With
Next