乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何在同一文件夹里多个excel名称后面加相同的字?(excel后面加字)

如何在同一文件夹里多个excel名称后面加相同的字?(excel后面加字)

作者:乔山办公网日期:

返回目录:excel表格制作

答:在文件夹下新建一个excel文件,新建个宏输入下面的vba代码,点运行宏,再把你新建的那个excel文件删除。

Sub 批量添加修改同目录下工作薄名称()

Dim f As String, wb As Workbook, th As Workbook, t As String, m As String, oldpath As String

Set th = ThisWorkbook

Application.ScreenUpdating = False '关闭刷屏

Application.DisplayAlerts = False '关闭警告和消息

f = Dir(th.Path & "\*.xls") '获取文件夹地址 许同一个版本:xls

t = InputBox("输入工作簿名称后需要添加的内容")

Do While f > " "

If f <> th.Name Then '判断是否为当前工作表

Set wb = Workbooks.Open(th.Path & "\" & f)

m = Left(f, InStrRev(f, ".") - 1)

wb.SaveAs (th.Path & "\" & m & t & ".xls") '保存为新工作薄

oldpath = th.Path & "\" & m & ".xls"

Kill (oldpath) '删除原工作簿

wb.Close

End If

f = Dir

Loop

Application.DisplayAlerts = True

Application.ScreenUpdating = True '恢复刷屏

End Sub


本文标签:

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网