Disable a macro, with another macro. EXCEL VBA
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
add a comment |
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
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
add a comment |
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
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
microsoft-excel vba macros
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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:
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-modulstore 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
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-modulstore 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
add a comment |
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:
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-modulstore 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
add a comment |
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:
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-modulstore 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
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:
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-modulstore 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
answered Dec 17 at 13:27
Máté Juhász
14.1k63150
14.1k63150
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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