Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何复制隐藏的工作表而新复制的工作表不隐藏?_Excel_Vba_Copy_Hidden - Fatal编程技术网

Excel 如何复制隐藏的工作表而新复制的工作表不隐藏?

Excel 如何复制隐藏的工作表而新复制的工作表不隐藏?,excel,vba,copy,hidden,Excel,Vba,Copy,Hidden,我想使用VBA复制隐藏的工作表。但是,当它运行vba代码时,所有复制的工作表都会被隐藏,请问是否有任何方法可以复制工作表,并且新创建的工作表不会被隐藏?我的VBA代码如下所示: Sub CopySheet() Sheet6.Copy After:=Sheets(Sheets.Count) End Sub 请尝试: Sheet6.Copy After:=Sheets(Sheets.count) Sheets(Sheets.count).Visible = xlSheetVisible

我想使用VBA复制隐藏的工作表。但是,当它运行vba代码时,所有复制的工作表都会被隐藏,请问是否有任何方法可以复制工作表,并且新创建的工作表不会被隐藏?我的VBA代码如下所示:

Sub CopySheet()
 
Sheet6.Copy After:=Sheets(Sheets.Count)
 
End Sub
请尝试:

Sheet6.Copy After:=Sheets(Sheets.count)
Sheets(Sheets.count).Visible = xlSheetVisible
隐藏分为两个阶段,xlSheetHidden和xlSheetVeryHidden。在我的Excel 365上,您的代码适用于普通隐藏的工作表,而在非常隐藏的工作表上崩溃。在这两种情况下都没有隐藏副本。但是,下面的代码将取消隐藏图纸,创建一个可见副本,并将原始文件再次隐藏到与以前相同的级别,所有这些对用户来说都是不可见的。因此,此代码可用于复制任何图纸,而不管其
Visible
属性的设置如何。它也应该适用于旧版本的Excel

Sub CopySheet()
 
    Dim Visible     As XlSheetVisibility
    
    Application.ScreenUpdating = False      ' hide the action from view
    With Sheet6
        Visible = .Visible                  ' record the sheet's visibility setting
        .Visible = xlSheetVisible           ' make the sheet visible
        .Copy After:=Sheets(Sheets.Count)   ' create a copy (the copy will be ActiveSheet)
        .Visible = Visible                  ' reset the sheet's Visible property to what it was before
    End With
    Application.ScreenUpdating = True
End Sub

为什么不干脆取消隐藏副本呢?因为有些用户从来不使用excel,也不知道如何在代码中取消隐藏副本?你可以像htat一样创建副本,同时取消隐藏副本谢谢你,它对我来说非常适合!
Sub CopySheet()
 
    Dim Visible     As XlSheetVisibility
    
    Application.ScreenUpdating = False      ' hide the action from view
    With Sheet6
        Visible = .Visible                  ' record the sheet's visibility setting
        .Visible = xlSheetVisible           ' make the sheet visible
        .Copy After:=Sheets(Sheets.Count)   ' create a copy (the copy will be ActiveSheet)
        .Visible = Visible                  ' reset the sheet's Visible property to what it was before
    End With
    Application.ScreenUpdating = True
End Sub