复制工作表并获取结果工作表对象? [英] Copy sheet and get resulting sheet object?

查看:120
本文介绍了复制工作表并获取结果工作表对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何简单/简短方法来获取复制工作表时获得的 new 工作表的工作表对象?

Is there any easy/short way to get the worksheet object of the new sheet you get when you copy a worksheet?

ActiveWorkbook.Sheets("Sheet1").Copy after:=someSheet

事实证明,.Copy方法返回布尔值而不是工作表对象.否则,我可以这样做:

It turns out that the .Copy method returns a Boolean instead of a worksheet object. Otherwise, I could have done:

set newSheet = ActiveWorkbook.Sheets("Sheet1").Copy after:=someSheet

因此,我写了大约25行代码来获取对象.列出复印之前的所有图纸,列出之后的所有图纸,并找出仅第二个列表中的哪一张.

So, I wrote some 25 lines of code to get the object. List all sheets before the copy, list all sheets after, and figure out which one is in the second list only.

我正在寻找一种更优雅,更短的解决方案.

I am looking for a more elegant, shorter solution.

推荐答案

Dim sht 

With ActiveWorkbook
   .Sheets("Sheet1").Copy After:= .Sheets("Sheet2")
   Set sht = .Sheets(.Sheets("Sheet2").Index + 1)
End With

这篇关于复制工作表并获取结果工作表对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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