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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing 'Save As' on Excel 2007 Workbook 1

Status
Not open for further replies.

Jacqui1811

Programmer
Jul 8, 2002
100
0
0
SG
Hi there,
I am in need of a push again :).
I want to stop the save as buttons working on an opened excel 2007 workbook.
I am also trying to disable the copy, cut and save opetions as well.
Here is the code I am using to open it and what I have already to try and stop the save as and other things.

Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();

string value = "C:/temp/users.xls";

xlWorkBook = xlApp.Workbooks.Open(value, 0, 1, 5, "", "", 1, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

CommandBars cmdbars = xlApp.CommandBars;

//Controls[0].Enabled = false;
for (int i = 1; i < cmdbars.Count; i++)
{
string name = cmdbars.Name.ToString();

for (int c = 1; c < cmdbars.Controls.Count; c++)
{
int control_id;
control_id = cmdbars.Controls[c].Id;
string control_name;

if (control_id == 21 || control_id == 19 || control_id == 3 || control_id == 846
|| control_id == 748 || control_id == 3823 || control_id == 848)
{
CommandBarControl cbc = cmdbars.Controls[c];
control_name = cmdbars.Controls[c].DescriptionText.ToString();
cbc.Enabled = false;
cbc.Visible = false;
cmdbars.Controls[c].Delete(cbc);
}
}
}

If I use this code the excel sheet opens normally except that if I try and save it says I have to save as as per the read only setting.

Thanks again.
Jacqui.
 
if you don't want this data copied, don't release it.

it would be much easier for you to come to terms with the fact that you've released it into the world and no longer control it than it would be for you to try to code round what you're proposing.

the users can always copy your spreadsheet and change its name in dos/explorer.

if they have to they can print it out then scan it and use OCR.

get used to it.

mr s. <;)

 
Hey trust me, I have explained this to my boss but !!!!!.
That is the way they want it, 'ours is not to wonder why, ours is just to do or get the sack', if you know what I mean :)
Jacqui
 
change jobs. the person asking for this is a moron.

tell them about the dos, and about the fact that whatever you code, the user can turn macros off and your work will be wasted.

mr s. <;)

 
on reflection, very few people are actually morons, and, unless you're dilbert, your boss os unlikely to be a pointy-haired computer ignoramus.

so, paranoia kicks in.

it's a test. they're testing your ability to deal with failure. they are asking you to do something they know you cannot in order to see what you do.

the worst option for them is that you solve the insovable, they have to give you a raise and, probably, greater responsibility. if you're that much more talented than they are they'll probably feel threatened and have to let you go.

next worst option you spend a great deal of time coding a heath robinson (rube goldberg?) "solution" which doesn't work. time wasters need sacking, or at the very least a black mark. of course, if they really are a moron you could code it to work in incredibly narrow circumstances (by turning off the menu options, say, which will only annoy your users) and they'd be satisfied, in which case you really should stay there for ever.

i'd say (and, sadly, i know nothing) that your best option is to prepare a better case. i'm guessing it's what's expected.
show them what the "options" are, and then show exactly why they don't work.
be more creative. how many ways can you think of to copy a file and.or its contents under windows and/or os/x? how may of those ways can be turned off and under what circumstances can they be turned back on again.
be more persuasive. i know that sales is the lowest legal form of human activity (somewhere between begging and mugging) but sometimes it's useful.

i hope this helps.


mr s. <;)

 
You could, in the Workbook BeforeSave method, set Cancel to true.

This should prevent it from being saved, although as mr s has stated - there are many ways around it, although it's usually quite sufficient for the non-computer literate which is a lot of end-users I have found!
 
I know there are soooooo many ways around it but my boss wants it as it is part of what our customer is asking for so as far as he is concerned it needs to be done no matter what.
I have explained everything about it to him and he just shrugged his shoulders and said it needed to be done.
I will give your idea a go anyway @PGO01 and let you know as soon as I have managed to test it.
Thanks.
Jacqui.
 
@PGO01.
Sorry it took so long to get back but I was given higher priority stuff for a while.
Anyway back on to this, I used that and it does the trick perfectly.
Many Thanks.
Jacqui.
 

maybe this works for you:

Private Sub beforesave(ByVal Wb As Microsoft.Office.Interop.Excel.Workbook, ByVal SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles XlApp.WorkbookBeforeSave

Cancel = True

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top