This project is read-only.

How to block the execution of makro's or VBA formulas in Excel 2007 - C#

Feb 13, 2013 at 8:19 AM
Hi all, is any way to block an excel makro's execution or VBA formulas that check (or calculate) cells. I have to work with not my own excel file that is protected by password. I can open file, add data and save it. Finally the file has 0 byte and I can not open it by Excel.

// C# code
using System;
using System.Linq;
using System.Text;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;

//open file
FileStream fs;
fs = new FileStream("Invoice list - Form.xls", FileMode.Open, FileAccess.Read);

this.wb = new HSSFWorkbook(fs, true);
this.ws = wb.GetSheet("Form 1");

// fill out a cell
ws.GetRow(4).GetCell(6).SetCellValue("Invoice number");

//save file
FileStream fsw = new FileStream("Invoice list.xls", FileMode.Create, FileAccess.Write);
this.wb.Write(fsw);
fsw.Close();