[问题] 工作表合并,不要放副档名

楼主: SergioLeone (穷穷)   2023-03-05 03:30:32
(若是和其他不同软件互动之问题 请记得一并填写)
软件:
版本:excel xlsx
简单描述一下状况好
我有一个资料夹
里面有二十个excel
每个excel都有五个工作表
分别是 资产 负债 权益 资产分析 负债分析
我输入以下VBA
把每个excel里面的‘’资产分析‘’
抓出来合并到一个excel
合并后的excel会有20个工作表
工作表名称以原本二十个excel的名称命名
但是后面会加上.xlsx
VBA代码:将工作簿的指定工作表合并到主工作簿中:
Sub MergeSheets2()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
Dim xI As Integer
On Error Resume Next
xStrPath = " C:\Users\a0921\Desktop\科余\"
xStrName = "资产分析"
xArr = Split(xStrName, ",")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
xStrFName = Dir(xStrPath & "*.xlsx")
Do While Len(xStrFName) > 0
Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
xStrAWBName = ActiveWorkbook.Name
For Each xWS In ActiveWorkbook.Sheets
For xI = 0 To UBound(xArr)
If xWS.Name = xArr(xI) Then
xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.count)
Set xMWS = xTWB.Sheets(xTWB.Sheets.count)
xMWS.Name = xStrAWBName
Exit For
End If
Next xI
Next xWS
Workbooks(xStrAWBName).Close
xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
这样合并完之后
每个工作表的名称都会带有.xlsx
我还需要一个一个删除
想请问高手如何不要有.xlsx呢
拜托 愿赠特大星巴克予以解惑之人
作者: waiter337 (给开司一罐苏格登)   2023-03-05 08:46:00
xMWS.Name = replace(xStrAWBName,".xlsx","")

Links booklink

Contact Us: admin [ a t ] ucptt.com