+ Reply to Thread
Results 1 to 6 of 6

Command Button to disable VBA code?

  1. #1
    Registered User
    Join Date
    02-22-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2003
    Posts
    9

    Command Button to disable VBA code?

    Hey everyone,

    I have this code set up which basically just hides every other column during printing. I was wondering if there was a way to have a button on the sheet somewhere that when clicked allows this code to be ignored. The columns hidden from the print are just filler data in a sense and it only prints the important columns but some people in the company would like the ability to see all the data and not just the important stuff.

    Thanks in advance




    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Command Button to disable VBA code?

    Hi, smohs14,

    you can use almost anything for that: Data/Validation, Checkbox, ToggleButton.

    But I would recommend to check the name of the person using the computer by environ("Username") in a Select Case.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,411

    Re: Command Button to disable VBA code?

    I'd suggest you have a global boolean variable. Your button could toggle it on or off and the print code would test it before hiding the columns or not.

    This shorter version of the code shows how the boolean variable would be used to control hiding the columns

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    02-22-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Command Button to disable VBA code?

    I'm gonna need a walk through or something with making buttons and how to link them to a command code because I've never made one before.

    It's my understanding that "If bHideColumns Then" means that when the button is clicked it hides the columns for printing but how do you actually set up the button. This is my first time using vba so it's been taking me a while to grasp everything.

  5. #5
    Registered User
    Join Date
    02-22-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Command Button to disable VBA code?

    actually a check box would be perfect if that's easily interchangeable as well

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,411

    Re: Command Button to disable VBA code?

    In a standard module:

    Please Login or Register  to view this content.

    In the sheet with the button

    Please Login or Register  to view this content.

    In the workbook module:

    Please Login or Register  to view this content.

    On the Developer tab, insert an ActiveX button ... should be CommandButton1.

    Copy the code above to the designated modules and ... with some luck ... it should sort itself out.


    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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