我需要找到一个Excel文件。然而,我寻找的文件的扩展名可能是.xls或.xlsx。我正在考虑使用FileExists,但是我不能使用通配符,下面是我使用GetFiles的尝试,但是,.xls *部分。我的代码不工作,我以前从未使用过的GetFiles,任何人都可以给我我做错了一些指导.NET通过使用通配符的GetFiles找到.xls或.xlsx文件?例如:.xls *
Dim InputFormPath As String = "W:\TOM\ERIC\NET Dev\"
Dim wbNameXLSInputForm As String = StatVar.xlApp.Sheets("New Calculator Input").Range("D15").Text & ".xls*"
Dim XLSInputForm As String = wbNameXLSInputForm
Dim dirs As String() = Directory.GetFiles(InputFormPath, wbNameXLSInputForm)
If dirs.Length <> 0 Then
'do something
End If
显然,您正在做的很好。应该在你的情况下工作:InputFormPath&StatVar.xlApp.Sheets(“New C. (“D15”).Text&“.xls *”和“*”&InputFormPath&StatVar.xlApp.Sheets(“New Calculator Input”)。范围(“D15”).Text&“。 xls“有了这两个过滤器,你应该同时获得xls和xlsx版本(以及其他任何类似xlsm的版本)。 – varocarbas
正在使用DimXLSInputForm以及wbNameXLSInputForm定义在哪里? –
@ SeanCarroll ...发布时切换我的变量,只是编辑我的文章,并添加 –