Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Button does not work on second click
I have button1 assigned ot the following macro on the 'headerpage' worksheet of my workbook. When the button is clicked it makes the 'Instruction' worksheet visible and active. Sub hide_sheet() ' Static fOn As Boolean fOn = Not fOn Sheets("Instructions").Visible = True = fOn Sheets("Instructions").Select End Sub On the 'Instruction' worksheet I have button2 with the following code. THis takes the user back to the 'headerpage' worksheet and rehides the 'instruction' worksheet. Sub hide_instruction2() ' Static fOff As Boolean Sheets("HeaderPage").Select fOn = Not fOn Sheets("Instructions").Visible = False = fOn End Sub THE ISSUE When youy click on button1 for the first time it works fine, then click on button to and it indeed does take the user back to the 'headerpage' worksheet and rehides the 'instruction' worksheet. However, if I click on button1 again it gives me a 'runtime error 1004' and highlights the line 'Sheets("Instructions").Select' in the Sub hide_sheet() macro assigned to button 1. Why? and how do I get this to work so no matter howmany times the user wants to switch back and forth between the two pages it will allow them to? Thanks Dan -- retseort ------------------------------------------------------------------------ retseort's Profile: http://www.excelforum.com/member.php...o&userid=24690 View this thread: http://www.excelforum.com/showthread...hreadid=483613 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Button does not work on second click
Hi,
Unless (and I may have!) I misunderstand what you want, the following "flips" between the worksheets - "Headerpage" is ALWAYS visible(?) Sub hide_sheet() Sheets("Instructions").Visible = True Sheets("Instructions").Select End Sub Sub hide_instruction2() Sheets("HeaderPage").Select Sheets("Instructions").Visible = False End Sub HTH "retseort" wrote: I have button1 assigned ot the following macro on the 'headerpage' worksheet of my workbook. When the button is clicked it makes the 'Instruction' worksheet visible and active. Sub hide_sheet() ' Static fOn As Boolean fOn = Not fOn Sheets("Instructions").Visible = True = fOn Sheets("Instructions").Select End Sub On the 'Instruction' worksheet I have button2 with the following code. THis takes the user back to the 'headerpage' worksheet and rehides the 'instruction' worksheet. Sub hide_instruction2() ' Static fOff As Boolean Sheets("HeaderPage").Select fOn = Not fOn Sheets("Instructions").Visible = False = fOn End Sub THE ISSUE When youy click on button1 for the first time it works fine, then click on button to and it indeed does take the user back to the 'headerpage' worksheet and rehides the 'instruction' worksheet. However, if I click on button1 again it gives me a 'runtime error 1004' and highlights the line 'Sheets("Instructions").Select' in the Sub hide_sheet() macro assigned to button 1. Why? and how do I get this to work so no matter howmany times the user wants to switch back and forth between the two pages it will allow them to? Thanks Dan -- retseort ------------------------------------------------------------------------ retseort's Profile: http://www.excelforum.com/member.php...o&userid=24690 View this thread: http://www.excelforum.com/showthread...hreadid=483613 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Button does not work on second click
You were correct and your code offering worked great...you are truly a GREAT ONE. THANKS :) :) :) :) -- retseort ------------------------------------------------------------------------ retseort's Profile: http://www.excelforum.com/member.php...o&userid=24690 View this thread: http://www.excelforum.com/showthread...hreadid=483613 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro recording won't record mouse click of add-in app button | Excel Discussion (Misc queries) | |||
Not able to Click Button placed in the Work Sheet | Excel Worksheet Functions | |||
Call Userfor and click button with macro | Excel Programming | |||
Can't start macro via button click | Excel Programming | |||
How do I set a macro to run when I click a Command Button in Exce. | Excel Programming |