gpt4 book ai didi

vba - 更改复制的选项卡的名称

转载 作者:行者123 更新时间:2023-12-03 03:21:31 26 4
gpt4 key购买 nike

我有一些 vba 代码,在下面我循环遍历模板文件的目录,打开任何具有 .xlsx 扩展名的文件,并将每个工作簿中的“报告”选项卡复制到 wbTarget 工作簿。我可以复制工作表,但我想更改已复制到变量 Filename 中的选项卡的名称。

    Public Sub CopySheets()

Dim wbk As Workbook
Dim Filename As String
Dim Path As String
Path = "C:\combine\"
Filename = Dir(Path & "*.xlsx")
Set wbTarget = ActiveWorkbook

Do While Len(Filename) > 0
Set wbk = Workbooks.Open(Path & Filename)
Sheet = 2
wbk.Sheets("Reporting").Copy After:=Workbooks("Combined.xlsm").Sheets(Workbooks("Combined.xlsm").Sheets.Count)

'>>change name of copied tab here<<

wbk.Close True
Filename = Dir
Sheet = Sheet + 1
Loop
End Sub

最佳答案

此行之后

wbk.Sheets("Reporting").Copy After:=Workbooks("Combined.xlsm").Sheets(Workbooks("Combined.xlsm").Sheets.Count) 

尝试

ActiveSheet.Name = "myname" '<== replace with whatever name you want to assign to the tab

关于vba - 更改复制的选项卡的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50676356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com