+ Reply to Thread
Results 1 to 20 of 20

Toggle Button on Workbook Open - value is True but button not pressed?

  1. #1
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Toggle Button on Workbook Open - value is True but button not pressed?

    Hi all,

    I have a toggle button (named 'toggle') on a worksheet to turn a function on and off (this all works fine). However, I need to always have the toggle button 'on' when the workbook is opened, and it is currently not working correctly.

    I have 'Sheets("Sheet 1").toggle.Value = True' (not text True) in a Workbook_Open() event, and this is setting the linked cell to True on the workbook opening.

    However, the toggle button isn't 'depressing' to show the user the function is turned on?? But the function is still on and working fine??

    So I need to know how to make the button turn on, but also depress to show it's 'clicked on'. Can anyone help please?

    In addition, is there anyway to change the words on the toggle button to 'On' or 'Off', depending whether the button is pressed down or not? This is just a secondary question, would be great if anyone has an answer to this but it's not important :-)

    Thanks all,
    Nat :-)

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Where did you put the workbook Open code?

    Is there any other code that could affect the togglebutton or linked cell?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Quote Originally Posted by Norie View Post
    Where did you put the workbook Open code?

    Is there any other code that could affect the togglebutton or linked cell?

    Thanks for your quick reply Norie :-)

    The Workbook Open code is in the ThisWorkbook code.

    No, I had a VBA If statement dependent upon the Linked Cell (K1), but I changed this already, so that when pressed, the linked cell changes through TRUE/FALSE and now another cell (L1) changes to "On"/"Off" and the If statement now depends on that cell. So now, it's only the Workbook open code that affects the toggle button and nothing else is dependant/linked to the linked cell

    NAt

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Can you post the exact code you are using in the workbook's Open event?

    I tried it with this and it seemed to work fine.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Hi, yeah it is as follows (I hope I've done this right!):

    Note that following your above post, I did originally have 'toggle.Value = True', I have now changed this to 'toggle = True' and it still doesn't depress the button!

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    That code looks fine.

    When you run it manually (F5) is the toggle button depressed?

    By the way, you should use Value, I was just being lazy/forgetful.

  7. #7
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    I've not tried that before (didn't know how haha) but yes! It DOES depress the button!

    The code runs, the welcome message appears and the button then presses down. then, when I open the file, the welcome message pops up and the button stays up

    I really appreciate your help btw, thank you!! :-)

  8. #8
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Also, I don't know if it will help, but I'm using the codes from http://excelribbon.tips.net/T008192_...nactivity.html for the timer function and I wanted to add in the toggle button to turn it off or on...

    Nat :-)

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    I wouldn't think the code for the timer would affect setting the toggle button.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  10. #10
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    I would as I want to get this sorted, however the file contains Data Protected information and it would take me an age to strip the workbook of all sensitive details. Is there a quick/safe way to upload the file or parts of it? Sorry, I've not done this before! :-)

    Nat :-)

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Can you not make a copy and delete all the data but leave the toggle button and code?

  12. #12
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Argh! Now I've stripped all the data out of the Doc the button is working fine! On opening, I get the welcome message and then the button presses on straight away... I've attached the sample doc.


    However... by mistake, I've just noticed that the button IS actually pressing after opening, but it is taking 16 seconds to press down after I click OK on the welcome message. I'm guessing that some code must be slowing it down in that case?
    Attached Files Attached Files

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Perhaps the timer code is causing the problem

    Try shifting the call to that code after everything else.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    :-( No, that hasn't solved it :-(

    I think it will just have to stay as it is unfortunately :-( At least it serves its purpose :-)

    Thank you for all your help :-)

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    What does ClearScreen do?

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Almost forgot this will toggle the caption, put it in the change event of the toggle button
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    It selects the unlocked cells on Sheet 1 and clears contents and clears some dependent cells on other sheets. So if the previous user has saved the file with info in the cells, ClearScreen empties them, resetting the form (sheet 1):

    Please Login or Register  to view this content.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Don't know if it'll make any difference but you could do that without selecting.
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Quote Originally Posted by Norie View Post
    Almost forgot this will toggle the caption, put it in the change event of the toggle button
    Please Login or Register  to view this content.

    That's fab!!! Thank you :-)

  20. #20
    Registered User
    Join Date
    03-10-2014
    Location
    Sheffield, UK
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Toggle Button on Workbook Open - value is True but button not pressed?

    Thanks for that, I'm just learning how to do things without Select as I know it speeds the calculations up, and I wasn't sure how to write the ClearContents bit without Select so I didn't want to ruin anything! So thanks for that, a great help :-D

    Also, I think I've found a way around the toggle button problem...

    In the BeforeClose event, I've changed the button to always be set to 'on' when the workbook is closed:

    Please Login or Register  to view this content.

    Seems to be working, even if it is a bit of a bodge!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Toggle Button in Ribbon Excel UI - After Reopening file it is not pressed
    By marzoumm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2014, 09:33 AM
  2. [SOLVED] Toggle the name of a button when pressed
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2013, 03:29 PM
  3. [SOLVED] Toggle Button 'State' Problem on Workbook Open
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2012, 06:35 AM
  4. [SOLVED] Toggle Button & getting the postion of the just pressed button
    By NugentS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2012, 11:58 AM
  5. Replies: 2
    Last Post: 02-13-2011, 01:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1