循环一直在工作,直到我添加了 If/ElseIf 语句来区分以“N”或“V”开头的两个不同文件。一切似乎都很好,但在它最初循环之后,它会直接通过 If 语句跳到否则。我在本地窗口中观看,它正在正确分配下一个文件,但是脚本将其视为开始时没有“V”,而实际上确实如此。建议?谢谢!
这是有问题的部分:
folderPath = myDir
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wbkCS = Workbooks.Open(folderPath & filename)
If filename = Dir(folderPath & "V*" & "*.xls") Then
wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy
With wbkVer.Worksheets("Cutsheets")
.Range("A" & .Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
ElseIf filename = Dir(folderPath & "N*" & "*.xls") Then
wbkCS.Worksheets("PON Cut Sheet").Range("AV3:AV2000").Copy
With wbkVer.Worksheets("Cutsheets")
.Range("A" & .Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
End If
filename = Dir
Loop
Application.ScreenUpdating = True