Consulting

Results 1 to 10 of 10

Thread: Solved: Enable & Disable Macro

  1. #1
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location

    Solved: Enable & Disable Macro

    Can I disable macro in worksheet events?
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  2. #2
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    ?
    [vba]
    Private Sub Worksheet_Deactivate()
    ActiveWorkbook.RunAutoMacros (xlAutoOpen)
    End Sub

    Private Sub Worksheet_Activate()
    ActiveWorkbook.RunAutoMacros (xlAutoClose)
    End Sub
    [/vba]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is the question regarding post #2?

  4. #4
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    I just tried to enter the code like that and it seems it doesnt work at all...
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Then I am confused. You ask about disabling macros, then show code to run macros.

    What exactly are you trying to do?

  6. #6
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    I want to Disable Macros in a worksheet event if its possible?
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you want to disable all macros in someone else's workbook, you have to open it with macros disabled. If you want to stop macros running from within your workbook, you will need to stop them manually, with some sort of flag setting. If you just don't want users to run macros from Excel, add Option Private Module at the start of the modules.

  8. #8
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    To disable event code use Application.EnableEvents = False (and don't forget to set it back to True later)
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  9. #9
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  10. #10
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    I've got full of option,information,idea to take. Thanks people...
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

Posting Permissions

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