Tag: savechanges

使用VBA通过C#禁用在Excel中保存function

我有一个function,我需要保护Excelfile upload到服务器,无法编辑,甚至保存。 为了实现这一点,我以编程方式保护文件,并添加了一些VBA代码限制了用户可以使用它。 VBA代码函数假设有2个function,可以隐藏function区并阻止Save / SaveAsfunction。 你可以参考我的代码里面有3个版本的VBA代码,但最希望的是其中的3号VBA代码。 这是我的function,我将文件位置的string传递给这个function。 我希望有人可以帮助我如何让程序保存安全的Excel文件(使用VBA代码no.3)。 从我的理解,我不能保存由于VBA代码保存 (不保存 )部分将不会允许这行wbkExcel.Save()进行。 您可以在Excel文件中testingVBA代码,看看它是否正常工作(到目前为止,testing对我有用…) 在此先感谢大家… protected void ExcelEncryptor(string strExcelFile) { Microsoft.Office.Interop.Excel.Application wAppExcel = new Microsoft.Office.Interop.Excel.Application(); wAppExcel.Interactive = false; wAppExcel.Visible = true; wAppExcel.DisplayAlerts = false; wAppExcel.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable; Microsoft.Office.Interop.Excel.Workbook wbkExcel = wAppExcel.Workbooks.Open(strExcelFile.ToString(),System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value); string strVBCode = string.Empty; //To hide Ribbon only /*strVBCode = "Private Sub Workbook_Open()\r\n" + " […]