如何复制隐藏的工作表并且新复制的工作表不隐藏?
How to copy a hidden worksheet and the new copied worksheet is not hidden?
我想使用 VBA 复制隐藏的工作表。但是,当它 运行 vba 代码时,所有复制的工作表也被隐藏,请问有什么方法可以复制工作表而不隐藏新创建的工作表吗?我的VBA代码如下:
Sub CopySheet()
Sheet6.Copy After:=Sheets(Sheets.Count)
End Sub
Sub CopySheet6()
Sheet6.Copy After:=Sheets(Sheets.Count)
Worksheets("Sheet6 (" & Sheets.Count - 1 & ")").Visible = True
End Sub
请尝试:
Sheet6.Copy After:=Sheets(Sheets.count)
Sheets(Sheets.count).Visible = xlSheetVisible
有Hidden两个阶段,xlSheetHidden和xlSheetVeryHidden。在我的 Excel 365 上,您的代码在正常 Hidden sheet 时工作,在 VeryHidden sheet 时崩溃.在这两种情况下,副本都没有被隐藏。但是,以下代码将取消隐藏 sheet,创建一个可见的副本并将原始副本再次隐藏到与之前相同的级别,所有这些对用户都是不可见的。因此,此代码可用于复制任何 sheet,而不管其 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
我想使用 VBA 复制隐藏的工作表。但是,当它 运行 vba 代码时,所有复制的工作表也被隐藏,请问有什么方法可以复制工作表而不隐藏新创建的工作表吗?我的VBA代码如下:
Sub CopySheet()
Sheet6.Copy After:=Sheets(Sheets.Count)
End Sub
Sub CopySheet6()
Sheet6.Copy After:=Sheets(Sheets.Count)
Worksheets("Sheet6 (" & Sheets.Count - 1 & ")").Visible = True
End Sub
请尝试:
Sheet6.Copy After:=Sheets(Sheets.count)
Sheets(Sheets.count).Visible = xlSheetVisible
有Hidden两个阶段,xlSheetHidden和xlSheetVeryHidden。在我的 Excel 365 上,您的代码在正常 Hidden sheet 时工作,在 VeryHidden sheet 时崩溃.在这两种情况下,副本都没有被隐藏。但是,以下代码将取消隐藏 sheet,创建一个可见的副本并将原始副本再次隐藏到与之前相同的级别,所有这些对用户都是不可见的。因此,此代码可用于复制任何 sheet,而不管其 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