简体   繁体   English

将粘贴格式从 sheet1 复制到新的附加工作表

[英]Copy paste format from sheet1 to new additional sheet

在此处输入图片说明

Sub Test()
    Dim ws1 As Worksheet
    Set ws1 = ThisWorkbook.Worksheets("Sample1")
    ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
End Sub

However, the problem is whenever I change sheet name, the code wouldn't run anymore.但是,问题是每当我更改工作表名称时,代码就不再运行。 So I decide to use the sheet codename which is Fixedtemplate(template)所以我决定使用固定模板(模板)的工作表代号

Sub Test()
    Dim ws1 As Worksheet
    Set ws1 = ThisWorkbook.Fixedtemplate
    ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
End Sub

There is still还有

compile error: Method or data member not found编译错误:未找到方法或数据成员

The code works below for me, you will need to provide either the name or the number of the sheet in order to copy the data.下面的代码适用于我,您需要提供工作表的名称或编号才能复制数据。

Sub main()
    Call Copydata("Fixedtemplate")
End Sub

Sub Copydata(name As String)
Dim ws1 As Worksheet
    Set ws1 = ThisWorkbook.Sheets(name)
    ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM