Jacqui1811
Programmer
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.
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.