|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 caibogang 于 2012-6-6 17:41 编辑
现在在做公共盘管理,其中有一个需求就是分析文件夹中的文件是否完整。问题是在我用VBA代码得到了文件名字以后,如何才能把文件名和路径名区分开来?坦白说,我认为VBA代码稍加修改就可以达到这个目的,但是因为我看不懂我得到的代码,所以还是想用公式来解决问题。
得到的文件名样本如下,所以\的数目并不是固定的,我现在只想到了用if和find来嵌套找到最后一个\在哪里,然后来区分。但是除此之外有更好的公式写法了吗?
P:\09_TAX\02_Plant_Package\02_Plant_Calamba\91_Tax_Report\00_EFPS\Monthly\2012\2012_01\Plant_Calamba_1601E_Confirmation_P1_2012.pdf
P:\09_TAX\02_Plant_Package\02_Plant_Calamba\91_Tax_Report\00_EFPS\Quarterly\2012\2012_Q1\Plant_Calamba_2550Q_Reference_Q1_2012.pdf
P:\09_TAX\02_Plant_Package\02_Plant_Calamba\91_Tax_Report\03_Fringe_Benefit\2012\2012_Q1\10_Workbook\K32104_Mar.xlsx
P:\09_TAX\02_Plant_Package\02_Plant_Calamba\91_Tax_Report\03_Fringe_Benefit\2012\2012_Q1\20_Report\Plant_Calamba_Fringe_Benefit_Q1_2012.xlsx
P:\09_TAX\02_Plant_Package\02_Plant_Calamba\91_Tax_Report\05_Value_Added_Tax\02_VAT_Relief_Textfile\2012\2012_Q1\234474332p012012.dat
P:\09_TAX\02_Plant_Package\02_Plant_Calamba\91_Tax_Report\05_Value_Added_Tax\01_VAT_Report\2012\2012_01\10_Workbook\JAN. C830.XLS
我得到的VBA代码如下,或者我应该如何修改这段代码,原代码出处见 http://club.excelhome.net/thread-355569-1-1.html
Private Sub CommandButton1_Click()
Dim MyName, Dic, Did, I, T, F, TT, MyFileName
T = Time
Set Dic = CreateObject("Scripting.Dictionary")
Set Did = CreateObject("Scripting.Dictionary")
Dic.Add ("P:\09_TAX\"), ""
I = 0
Do While I < Dic.Count
Ke = Dic.keys
MyName = Dir(Ke(I), vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(Ke(I) & MyName) And vbDirectory) = vbDirectory Then
Dic.Add (Ke(I) & MyName & "\"), ""
End If
End If
MyName = Dir
Loop
I = I + 1
Loop
Did.Add ("FileList"), ""
For Each Ke In Dic.keys
MyFileName = Dir(Ke & "*.*")
Do While MyFileName <> ""
Did.Add (Ke & MyFileName), ""
MyFileName = Dir
Loop
Next
For Each Sh In ThisWorkbook.Worksheets
If Sh.Name = "FileList" Then
Sheets("FileList").Cells.Delete
F = True
Exit For
Else
F = False
End If
Next
If Not F Then
Sheets.Add.Name = "FileList"
End If
Sheets("FileList").[A1].Resize(Did.Count, 1) = WorksheetFunction.Transpose(Did.keys)
TT = Time - T
MsgBox Minute(TT) & "M" & Second(TT) & "S"
End Sub
|
|