我寫的代碼可以顯示文件名到工作表中,但我想在顯示時刪除擴展名。我知道這應該是一個小改正,但我燒掉了嘗試選項。有人可以告訴我在哪裏必須添加一段我想錯過的代碼嗎?我嘗試下面的代碼。在網上很多類似的問題,但我不能設法提前發現it.Thanks ....如何刪除找到的文件的擴展名FSO?
Option Explicit
Sub fileNames_in_folder()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Dim fldpath
Dim fld As Object, fil As Object, fso As Object, j As Long
fldpath = "C:\"
On Error Resume Next
Thisworkbook.Sheets("1").Activate
'start count row
j = 11
Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.getfolder(fldpath)
For Each fil In fld.Files
'here I have to add something due to expell the ".extension"
Cells(j, 34).Value = fso.GetBaseName(fil.path)
'count behaviour
j = j + 1
Next
Columns("AH").AutoFit
End Sub
讓我們清楚說明 - 除了文件擴展名外,您希望保留整個路徑+文件名嗎? –
我更新了代碼!感謝伊萬,這就像一支矛! – user2151190