我目前有一个查找特定文件名的宏,并根据结果运行专门针对该文件的特定子:
Sub CommandButton3_Click()
Dim i As Integer
Dim fname As Variant
Dim filepath As Variant
'filepath = Application.GetOpenFilename(FileFilter:="Excel File (*.csv), *.scv")
fname = Application.GetOpenFilename(FileFilter:="Excel File (*.csv), *.scv",
Title:="Please select a stat file", MultiSelect:=True)
filepath = ThisWorkbook.Path
For i = 1 To UBound(fname)
If fname(i) = filepath & "\" & "Nodes.csv" Then
Workbooks.Open (fname(i))
Call Node
ElseIf fname(i) = filepath & "\" & "IOGroups.csv" Then
Workbooks.Open (fname(i))
Call IOGrp
ElseIf fname(i) = filepath & "\" & "ManagedDiskGroups.csv" Then
Workbooks.Open (fname(i))
Call MdiskGrp
ElseIf fname(i) = filepath & "\" & "ManagedDisks.csv" Then
Workbooks.Open (fname(i))
Call Mdisk
ElseIf fname(i) = filepath & "\" & "Ports.csv" Then
Workbooks.Open (fname(i))
Call Ports
ElseIf fname(i) = filepath & "\" & "Subsystem.csv" Then
Workbooks.Open (fname(i))
Call Subsystem
ElseIf fname(i) = filepath & "\" & "Volumes.csv" Then
Workbooks.Open (fname(i))
Call Volumes
Else
End If
Next i
End Sub
我希望能够在名称中包含 2 个通配符,即:
If fname(i) = filepath & "\" & "*Node*.csv" Then
这甚至有可能吗,需要这个的原因是文件的名称不同,但是每个文件名中的根词总是相同的,唯一的问题是根词之前和之后通常有一些东西。有任何想法吗?此外,目前包含此宏的工作簿必须与用于工作的文件位于同一目录中,有没有办法改变它?谢谢!