Disable a macro, with another macro. EXCEL VBA












0














I have 7 macros that prevent a user from copying and pasting in a workbook.



However, now and then I want to be able to copy and paste. Is there a way to disable these macros with another macro ?



I can only find information on how to disable all macros, and this does not seem achievable with another macro itself.



I would also want to be able to turn the macros back on, and plan to have this macro run whenever the workbook is closed, so that the next user, by default cannot copy and paste.



Below are the macros I use to prevent copying and pasting.



Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub









share|improve this question






















  • Create a mask variable variable on this module level with proper value. Perform the disabling action only if a bit of this variable is set. Alter this variable from Immediate, another macro or edit in code for permanent change.
    – Akina
    Dec 17 at 13:58


















0














I have 7 macros that prevent a user from copying and pasting in a workbook.



However, now and then I want to be able to copy and paste. Is there a way to disable these macros with another macro ?



I can only find information on how to disable all macros, and this does not seem achievable with another macro itself.



I would also want to be able to turn the macros back on, and plan to have this macro run whenever the workbook is closed, so that the next user, by default cannot copy and paste.



Below are the macros I use to prevent copying and pasting.



Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub









share|improve this question






















  • Create a mask variable variable on this module level with proper value. Perform the disabling action only if a bit of this variable is set. Alter this variable from Immediate, another macro or edit in code for permanent change.
    – Akina
    Dec 17 at 13:58
















0












0








0







I have 7 macros that prevent a user from copying and pasting in a workbook.



However, now and then I want to be able to copy and paste. Is there a way to disable these macros with another macro ?



I can only find information on how to disable all macros, and this does not seem achievable with another macro itself.



I would also want to be able to turn the macros back on, and plan to have this macro run whenever the workbook is closed, so that the next user, by default cannot copy and paste.



Below are the macros I use to prevent copying and pasting.



Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub









share|improve this question













I have 7 macros that prevent a user from copying and pasting in a workbook.



However, now and then I want to be able to copy and paste. Is there a way to disable these macros with another macro ?



I can only find information on how to disable all macros, and this does not seem achievable with another macro itself.



I would also want to be able to turn the macros back on, and plan to have this macro run whenever the workbook is closed, so that the next user, by default cannot copy and paste.



Below are the macros I use to prevent copying and pasting.



Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub






microsoft-excel vba macros






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 17 at 13:07









PeterH

3,44332246




3,44332246












  • Create a mask variable variable on this module level with proper value. Perform the disabling action only if a bit of this variable is set. Alter this variable from Immediate, another macro or edit in code for permanent change.
    – Akina
    Dec 17 at 13:58




















  • Create a mask variable variable on this module level with proper value. Perform the disabling action only if a bit of this variable is set. Alter this variable from Immediate, another macro or edit in code for permanent change.
    – Akina
    Dec 17 at 13:58


















Create a mask variable variable on this module level with proper value. Perform the disabling action only if a bit of this variable is set. Alter this variable from Immediate, another macro or edit in code for permanent change.
– Akina
Dec 17 at 13:58






Create a mask variable variable on this module level with proper value. Perform the disabling action only if a bit of this variable is set. Alter this variable from Immediate, another macro or edit in code for permanent change.
– Akina
Dec 17 at 13:58












1 Answer
1






active

oldest

votes


















0














Unfortunately transferring status / information between run of macros is not easy in VBA as no variables can persist between run of macros. You have two options:




  1. change the code from another macro

    Further reading: https://stackoverflow.com/questions/14811343/is-it-possible-in-excel-vba-to-change-the-source-code-of-module-in-another-modul


  2. store the status information in a cell.

    You can use e.g. right bottom corner cell of a spreadsheet as that is not regularly used by users.

    You can modify your code e.g.





Private Sub Workbook_Activate()
If Sheets(1).Range("XFD1048576") = "paused" Then
Exit Sub
End If
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1385244%2fdisable-a-macro-with-another-macro-excel-vba%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Unfortunately transferring status / information between run of macros is not easy in VBA as no variables can persist between run of macros. You have two options:




    1. change the code from another macro

      Further reading: https://stackoverflow.com/questions/14811343/is-it-possible-in-excel-vba-to-change-the-source-code-of-module-in-another-modul


    2. store the status information in a cell.

      You can use e.g. right bottom corner cell of a spreadsheet as that is not regularly used by users.

      You can modify your code e.g.





    Private Sub Workbook_Activate()
    If Sheets(1).Range("XFD1048576") = "paused" Then
    Exit Sub
    End If
    Application.CutCopyMode = False
    Application.OnKey "^c", ""
    Application.CellDragAndDrop = False
    End Sub





    share|improve this answer


























      0














      Unfortunately transferring status / information between run of macros is not easy in VBA as no variables can persist between run of macros. You have two options:




      1. change the code from another macro

        Further reading: https://stackoverflow.com/questions/14811343/is-it-possible-in-excel-vba-to-change-the-source-code-of-module-in-another-modul


      2. store the status information in a cell.

        You can use e.g. right bottom corner cell of a spreadsheet as that is not regularly used by users.

        You can modify your code e.g.





      Private Sub Workbook_Activate()
      If Sheets(1).Range("XFD1048576") = "paused" Then
      Exit Sub
      End If
      Application.CutCopyMode = False
      Application.OnKey "^c", ""
      Application.CellDragAndDrop = False
      End Sub





      share|improve this answer
























        0












        0








        0






        Unfortunately transferring status / information between run of macros is not easy in VBA as no variables can persist between run of macros. You have two options:




        1. change the code from another macro

          Further reading: https://stackoverflow.com/questions/14811343/is-it-possible-in-excel-vba-to-change-the-source-code-of-module-in-another-modul


        2. store the status information in a cell.

          You can use e.g. right bottom corner cell of a spreadsheet as that is not regularly used by users.

          You can modify your code e.g.





        Private Sub Workbook_Activate()
        If Sheets(1).Range("XFD1048576") = "paused" Then
        Exit Sub
        End If
        Application.CutCopyMode = False
        Application.OnKey "^c", ""
        Application.CellDragAndDrop = False
        End Sub





        share|improve this answer












        Unfortunately transferring status / information between run of macros is not easy in VBA as no variables can persist between run of macros. You have two options:




        1. change the code from another macro

          Further reading: https://stackoverflow.com/questions/14811343/is-it-possible-in-excel-vba-to-change-the-source-code-of-module-in-another-modul


        2. store the status information in a cell.

          You can use e.g. right bottom corner cell of a spreadsheet as that is not regularly used by users.

          You can modify your code e.g.





        Private Sub Workbook_Activate()
        If Sheets(1).Range("XFD1048576") = "paused" Then
        Exit Sub
        End If
        Application.CutCopyMode = False
        Application.OnKey "^c", ""
        Application.CellDragAndDrop = False
        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 17 at 13:27









        Máté Juhász

        14.1k63150




        14.1k63150






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1385244%2fdisable-a-macro-with-another-macro-excel-vba%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How do I know what Microsoft account the skydrive app is syncing to?

            Grease: Live!

            When does type information flow backwards in C++?