VBA复制表到工作簿的末尾(带有隐藏的工作表) [英] VBA Copy Sheet to End of Workbook (with Hidden Worksheets)

查看:725
本文介绍了VBA复制表到工作簿的末尾(带有隐藏的工作表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想复制一张工作表,并将其添加到所有当前工作表的末尾(无论工作表是否被隐藏)。

I want to copy a sheet and add it to the end of all current sheets (regardless of whether the sheets are hidden).

Sheets(1).Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).name = "copied sheet!"

这样做很好,除了当有隐藏的表单时,新的表单只会在最后一个可见的工作表,所以名称命令重命名错误的工作表。

This works fine, except, when there are hidden sheets, the new sheet is only inserted after the last visible worksheet, so the name command renames the wrong sheet.

我尝试过以下变体,以获得引用新复制的 WorkSheet ,但没有成功和/或有效的代码。

I have tried variations of the following to get a reference to the newly copied WorkSheet but none were successful and/or valid code.

Dim test As Worksheet
Set test = Sheets(1).Copy(After:=Sheets(Sheets.Count))
test.Name = "copied sheet!"


推荐答案

尝试这个

Sub Sample()
    Dim test As Worksheet
    Sheets(1).Copy After:=Sheets(Sheets.Count)
    Set test = ActiveSheet
    test.Name = "copied sheet!"
End Sub

这篇关于VBA复制表到工作簿的末尾(带有隐藏的工作表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆