选择多个文件并遍历所有文件以根据名称执行操作
Selecting multiple files and loop through all to perform actions based on names
我编写了一个代码,其中包含 select 多个文件的浏览对话框,并将文件名保存在数组中,并根据文件名中的关键字一个一个地循环执行操作。
- 因为它有多个 select 选项,我想根据文件名中的关键字执行特定操作
- 我卡在了数组中的循环文件名中。我不知道哪里出错了
- 如果我错了,请纠正我的语法,因为我很新,请多多包涵
至 VBA
感谢任何帮助
fNameAndPath = Application.GetOpenFilename(fileFilter:="Excel Files (*.CSV), *.CSV", Title:="Select File To Be Opened", MultiSelect:=True)
If Not IsArray(fNameAndPath) Then Exit Sub
For Each MyFile In fNameAndPath
Set wb = Workbooks.Open(MyFile)==========(how to search for specific file name in myfile array..
' do stuff with workbook that has been opened
if myfile= "*test_one*" then
Set Fnd1 = Range("A1")
Qty1 = WorksheetFunction.CountIf(Rows(1), "*shop3**high*")
For Cnt1 = 1 To Qty1
Set Fnd1 = Rows(1).Find("*shop3**high*",Fnd1, , xlWhole, , , False, , False)
max_num = Application.WorksheetFunction.Max(Fnd1.EntireColumn) ' maxnum value is copied to a cell in submit button
Next Cnt1
elseif myfile="*test_last*" then
'similar to macro1
elseif myfile=test3.csv then
similar to macro1
end if.
wb.Close SaveChanges:=False
Next MyFile
End Sub
if myfile= "*test_one*" then
如果您正在寻找文件名的一部分,那么您需要这样的东西:
If LCase(myfile) Like "*test_one*" Then
我编写了一个代码,其中包含 select 多个文件的浏览对话框,并将文件名保存在数组中,并根据文件名中的关键字一个一个地循环执行操作。
- 因为它有多个 select 选项,我想根据文件名中的关键字执行特定操作
- 我卡在了数组中的循环文件名中。我不知道哪里出错了
- 如果我错了,请纠正我的语法,因为我很新,请多多包涵 至 VBA
感谢任何帮助
fNameAndPath = Application.GetOpenFilename(fileFilter:="Excel Files (*.CSV), *.CSV", Title:="Select File To Be Opened", MultiSelect:=True) If Not IsArray(fNameAndPath) Then Exit Sub For Each MyFile In fNameAndPath Set wb = Workbooks.Open(MyFile)==========(how to search for specific file name in myfile array.. ' do stuff with workbook that has been opened if myfile= "*test_one*" then Set Fnd1 = Range("A1") Qty1 = WorksheetFunction.CountIf(Rows(1), "*shop3**high*") For Cnt1 = 1 To Qty1 Set Fnd1 = Rows(1).Find("*shop3**high*",Fnd1, , xlWhole, , , False, , False) max_num = Application.WorksheetFunction.Max(Fnd1.EntireColumn) ' maxnum value is copied to a cell in submit button Next Cnt1 elseif myfile="*test_last*" then 'similar to macro1 elseif myfile=test3.csv then similar to macro1 end if. wb.Close SaveChanges:=False Next MyFile End Sub
if myfile= "*test_one*" then
如果您正在寻找文件名的一部分,那么您需要这样的东西:
If LCase(myfile) Like "*test_one*" Then