[英]How to copy a hidden worksheet and the new copied worksheet is not hidden?
Hidden有兩個階段,xlSheetHidden 和 xlSheetVeryHidden。 在我的 Excel 365 上,您的代碼適用於普通的Hidden工作表,而對於VeryHidden工作表則崩潰了。 在這兩種情況下,副本都沒有被隱藏。 但是,下面的代碼將取消隱藏工作表,創建一個可見的副本並將原件再次隱藏到與以前相同的級別,所有這些對用戶都是不可見的。 因此,此代碼可用於復制任何工作表,而不管其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
請試試:
Sheet6.Copy After:=Sheets(Sheets.count)
Sheets(Sheets.count).Visible = xlSheetVisible
Sub CopySheet6()
Sheet6.Copy After:=Sheets(Sheets.Count)
Worksheets("Sheet6 (" & Sheets.Count - 1 & ")").Visible = True
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.