0
我有這個代碼獲取所有文件類型。那麼如果它在數組中有擴展名,它應該被存儲在excludedFile
數組中,並且將在執行後顯示。在數組中添加一個文件名
Dim excludedFile() as String
Const exts = _
".ade.adp.app.asp.bas.bat.cer.chm.cmd.com.cpl.crt.csh.der.exe.fxp.gadget" & _
".hlp.hta.inf.ins.isp.its.js.jse.ksh.lnk.mad.maf.mag.mam.maq.mar.mas.mat"
Dim file As Variant
file = Application.GetOpenFilename("All Files, *.*", , "Select File", , True)
ReDim data(1 To UBound(file) + 1, 1 To 1)
' filter the list
For i = LBound(file) To UBound(file)
ext = LCase(Mid(file(i), InStrRev(file(i), ".")))
If InStr(1, exts, ext & ".") = 0 Then ' if not blacklisted
count = count + 1
data(count, 1) = file(i)
Else 'I've tried this but returns Subscript out of range error
excludedFile(UBound(excludedFile)) = file(i)
ReDim Preserve excludedFile(1 To UBound(excludedFile) + 1) As String
found = true
End If
Next
if found then
MsgBox Join(excludedFile, vbCrLf)
end if
任何幫助表示讚賞。謝謝。
你可以發佈你的子代碼的其餘部分?它缺少'excludedFile'聲明數組。如果InStr(1,exts,ext&「。」)= 0那麼你也有一個類型錯誤,那麼''應該是'(1,ext,ext&「。」)'no? –
@ShaiRado更新了我的問題。而且它不是一個錯字:) – ramj
我必須缺少一些東西,你打開一個文件,那麼什麼數組?你有上面的另一個循環嗎?將文件夾中的所有文件都刪除;您需要使用'GetFolder'命令嗎? –