Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling save function in a new workbook after disabling it in current

Status
Not open for further replies.

novartis1

Technical User
Sep 26, 2008
8
US
Hello All,

I have sucessfuly disabled the save, save as, and other functions in the current workbook that I'm working on, but now these functions are disabled in any excel workbook I bring up. Is there a way to fix this? This is what my code currently looks like in "ThisWorkbook"

Code:
Private Sub Worksheet_WindowActivate(ByVal Wn As Window)
    Dim oCtrl As Office.CommandBarControl
    'Cut
    For Each oCtrl In Application.CommandBars.FindControls  (ID:=21)
        oCtrl.Enabled = False
    'Copy
    For Each oCtrl In Application.CommandBars.FindControls(ID:=19)
        oCtrl.Enabled = False
    'Save
    For Each oCtrl In Application.CommandBars.FindControls(ID:=3)
        oCtrl.Enabled = False
   'Save As
    For Each oCtrl In Application.CommandBars.FindControls(ID:=748)
        oCtrl.Enabled = False
    'Save as Web Page
    For Each oCtrl In Application.CommandBars.FindControls(ID:=3823)
        oCtrl.Enabled = False
    'Save as Workspace
    For Each oCtrl In Application.CommandBars.FindControls(ID:=846)
        oCtrl.Enabled = False
    'Move or Copy Sheet
    For Each oCtrl In Application.CommandBars.FindControls(ID:=848)
        oCtrl.Enabled = False
    'Ctrl C
    Application.OnKey "^c", ""
    'Ctrl S
    Application.OnKey "^s", ""
    Application.CellDragAndDrop = False
End Sub


Private Sub Worksheet_WindowDeactivate(ByVal Wn As Window)
    Dim oCtrl As Office.CommandBarControl
    For Each oCtrl In Application.CommandBars.FindControls(ID:=21)
        oCtrl.Enabled = True
    For Each oCtrl In Application.CommandBars.FindControls(ID:=19)
        oCtrl.Enabled = True
    For Each oCtrl In Application.CommandBars.FindControls(ID:=3)
        oCtrl.Enabled = True
    For Each oCtrl In Application.CommandBars.FindControls(ID:=748)
        oCtrl.Enabled = True
    For Each oCtrl In Application.CommandBars.FindControls(ID:=3823)
        oCtrl.Enabled = True
    For Each oCtrl In Application.CommandBars.FindControls(ID:=846)
        oCtrl.Enabled = True
    For Each oCtrl In Application.CommandBars.FindControls(ID:=848)
        oCtrl.Enabled = True
    Application.OnKey "^c", ""
    Application.OnKey "^s", ""
    Application.CellDragAndDrop = True
End Sub

Thank you for the help
 





Hi,

"... but now these functions are disabled in any excel workbook I bring up."

"bring up" in a conversation, regurgitation, elevator? ;-)

How are you bringing up these other workbooks: from the DISABLED one, otherwise?
Do each of these other workbooks have event code of there own that is also disabled?

How did you "disable" the code to begin with?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
First, excuse me for my imprecise diction, and second I have to admit that I am a relatively novice programmer. By bring up, I mean any time that I open a new excel workbook, either by selecting "File New" in the excel window that has the worksheet that contains this code, or after completely exiting out of excel, and re-opening a blank workbook. I have not manipulated any VBA code in the new workbooks. Lastly, I disabled the function with the first private sub by selecting the control ID and selecting "oCtrl Enabled = False"

Thanks,
Andy
 




That command should only disable that obejct.

Are you sure that you are not assigning the APPLICTION EnableEvents property. That WOULD disable ANY event for Excel, not just an object's events.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sorry, I haven't gotten back to you sooner, I've been preoccupied with other things, I will try your suggestions, and thank you very much for the help.

Thanks,

Andy
 
Hi skip,

It turned out to be a pretty simple problem. I moved the code to the "this workbook" and had to add a "Next oCtrl" after each Find control. I do appreciate the help however, and maybe I will get to the point where I don't have to bother other people for help, we'll see though.

Thanks,
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top