国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

實(shí)例44-獲取文件夾中的文件名稱,實(shí)例45-重命名文件 Excel程序VBA編程 代碼分享

2023-03-22 12:05 作者:凌霄百科_Excel辦公程序  | 我要投稿

實(shí)例44-獲取文件夾中的文件名稱



Private Sub CommandButton獲取_Click()

'---不包含文件夾

With ThisWorkbook.Worksheets("操作界面")

If Trim(.Cells(2, "C").Value) = "" Then

MsgBox "文件夾路徑參數(shù)不能為空"

Exit Sub

End If

Dim fpath As String

fpath = Trim(.Cells(2, "C").Value)

End With

Set fs = CreateObject("Scripting.FileSystemObject")

Set fs_folder = fs.GetFolder(fpath)

Call getfilename(fs_folder)

With ThisWorkbook.Worksheets("名稱列表")

.Columns(1).AutoFit

.Columns(2).AutoFit

.Activate

End With

End Sub

Sub getfilename(fso)

With Worksheets("名稱列表")

.UsedRange.ClearContents

Dim addrow

'--------------------------------------------------------------

.Cells(1, 1) = "完整路徑"

.Cells(1, 2) = "文件名"

addrow = .Cells(1000000, 1).End(xlUp).Row + 1

Dim f

For Each f In fso.Files

.Cells(addrow, 1) = f.Path

.Cells(addrow, 2) = "'" & f.Name

addrow = addrow + 1

Next

End With

End Sub

實(shí)例45-重命名文件



Private Sub CommandButton獲取_Click()

'---不包含文件夾

With ThisWorkbook.Worksheets("操作界面")

If Trim(.Cells(2, "C").Value) = "" Then

MsgBox "文件夾路徑參數(shù)不能為空"

Exit Sub

End If

Dim fpath As String

fpath = Trim(.Cells(2, "C").Value)

End With

Set fs = CreateObject("Scripting.FileSystemObject")

Set fs_folder = fs.GetFolder(fpath)

Call getfilename(fs_folder)

With ThisWorkbook.Worksheets("名稱列表")

.Columns(1).AutoFit

.Columns(2).AutoFit

.Activate

End With

End Sub

Sub getfilename(fso)

With Worksheets("名稱列表")

.UsedRange.ClearContents

Dim addrow

'--------------------------------------------------------------

.Cells(1, 1) = "完整路徑"

.Cells(1, 2) = "原文件名"

.Cells(1, 3) = "新文件名"

addrow = .Cells(1000000, 1).End(xlUp).Row + 1

Dim f

For Each f In fso.Files

.Cells(addrow, 1) = f.Path

.Cells(addrow, 2) = "'" & f.Name

addrow = addrow + 1

Next

End With

End Sub

Private Sub CommandButton重命名_Click()

With Worksheets("名稱列表")

Dim i, imax

imax = .Cells(1000000, 1).End(xlUp).Row

If imax = 1 Then

Exit Sub

End If

Dim old_name As String

Dim new_name As String

For i = 2 To imax

old_name = .Cells(i, 1)

new_name = Left(.Cells(i, 1), Len(.Cells(i, 1)) - Len(.Cells(i, 2)) - 1) & "\" & .Cells(i, 3)

Name old_name As new_name

Next i

.Activate

MsgBox "處理完成"

End With

End Sub



實(shí)例44-獲取文件夾中的文件名稱,實(shí)例45-重命名文件 Excel程序VBA編程 代碼分享的評論 (共 條)

分享到微博請遵守國家法律
中西区| 金湖县| 射阳县| 逊克县| 舞钢市| 彰化县| 桦南县| 河间市| 曲阳县| 北辰区| 察雅县| 井研县| 汝州市| 日土县| 莒南县| 尼玛县| 武乡县| 黄平县| 元阳县| 荣昌县| 哈巴河县| 喀什市| 甘肃省| 丹凤县| 门源| 黄石市| 平原县| 兴山县| 义马市| 唐河县| 沁水县| 措美县| 红河县| 隆子县| 荔波县| 大名县| 临猗县| 大厂| 永州市| 永靖县| 额济纳旗|