VBA & Macro Problems

Copy a Hidden Template Sheet with an Excel VBA Macro

Phi Hung VoPhi Hung Vo Dec 2, 2026 869 views

Question details

The user needs a VBA macro that copies a hidden template worksheet and hides the template again afterward.

Copy a Hidden Template Sheet with an Excel VBA Macro
Product
Microsoft Excel
Device & OS
not provided
Scenario
Create a new worksheet from a hidden template within the workbook.
Observed behavior
Excel may not copy the template while it is hidden, so it needs to be made visible temporarily.
Before you start

Make sure the workbook contains a worksheet named Original and at least one other sheet, and that its workbook structure is not protected. Save it as a macro-enabled workbook (.xlsm) and enable macros only if you trust the file.

Solution 1Recommended

Temporarily Unhide and Copy the Template with VBA

Use this macro to copy the template before the second sheet and restore its previous visibility.

1
Open the VBA editor

In Excel, open the workbook and select Developer > Visual Basic. If Developer is not visible, enable it in Excel's ribbon settings.

2
Add the macro

In the VBA editor, select the workbook, choose Insert > Module, and paste: Sub CopyHiddenTemplate() Dim template As Worksheet Dim originalVisibility As XlSheetVisibility Set template = ThisWorkbook.Worksheets("Original") originalVisibility = template.Visible template.Visible = xlSheetVisible template.Copy Before:=ThisWorkbook.Sheets(2) template.Visible = originalVisibility End Sub

3
Run the macro

Return to Excel, select Developer > Macros, choose CopyHiddenTemplate, and click Run. A copy of Original appears before the second sheet.

Temporarily Unhide and Copy the Template with VBA
If the macro stops: If copying fails before the final line runs, Original may remain visible. Check its visibility in the VBA editor and hide it again if needed. ThisWorkbook refers to the workbook containing the macro.
Free Microsoft Office alternative

Work with Excel Templates in WPS Spreadsheet

WPS Office is a free, lightweight, easy-to-use Office alternative with a familiar interface. Open compatible Excel workbooks and continue working with their sheets as you move between office suites. It does not fix Excel VBA behavior, and macro support can vary by WPS version.

Open and work with Excel XLSX and XLSM filesManage worksheet templates in WPS SpreadsheetUse a familiar spreadsheet interface for easier migrationGet a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro make the template visible before copying it?

Excel may not copy a worksheet while it is hidden. Setting its Visible property to xlSheetVisible before calling Copy avoids that situation.

Will the macro preserve a very hidden template?

Yes. The macro stores the template's original Visible property and restores it after a successful copy, including xlSheetVeryHidden.

How do I change where the copied sheet appears?

Change Before:=ThisWorkbook.Sheets(2) to another destination, such as After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count), to place the copy at the end.

Why does the macro fail when changing sheet visibility?

Check whether the workbook structure is protected. In Excel, go to Review > Protect Workbook and remove structure protection if you have permission, then run the macro again.