- Work workbook is called
- It has two sheets called
Sheet1has a commandbutton called
Module1 I have the following code:
Sub Macro1() With Workbooks("Main.xlsm").Sheets("Sheet2") .Visible = True .Copy .Visible = xlVeryHidden End With End Sub
This code makes
Sheet2 visible, copies it as a new workbook (a new workbook pops up), then makes it
xlVeryHidden again. At this point, Main.xlsm is behind, newly created workbook is in front.
When I run
- I click the X (close) button of Main.xlsm, the Main.xlsm tries to close as it should be.
When I run
- This time the excel window flickers a few times. When I click the X (close) button of Main.xlsm, the newly opened excel workbook (Book#.xlsx) tries to close.
Question: What might be the reason of this?
PS: If this doesn't happen to you when you try the above, try the following and you will experience the same thing:
- Create a combobox on
cmb_listwith "Copy Sheet2" and "Copy Sheet3"
- Create another sheet called
Sheet3and make it
- Select any of the values in
cmb_listand run the following code from
Sub Macro3() With Workbooks("Main.xlsm") If cmb_list.Value = "Copy Sheet2" Then .Sheets("Sheet2").Visible = True .Sheets("Sheet2").Copy .Sheets("Sheet2").Visible = xlVeryHidden ElseIf cmb_list.Value = "Copy Sheet3" Then .Sheets("Sheet3").Visible = True .Sheets("Sheet3").Copy .Sheets("Sheet3").Visible = xlVeryHidden End If End With End Sub