Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Support for Excel Workbooks with VBA code problems
posted

hello,

sorry for my bad english.

i am trying to write to an existing excel file (.xls format).

this existing excel file has a macro in it.

the problem is when i try to save it (using Workbook.Save(targetfile)), it can be saved successfully but all the macros are gone.

here are my snippet codes :

Workbook ExistingWorkbook = new Infragistics.Documents.Excel.Workbook(WorkbookFormat.Excel2007MacroEnabled);
ExistingWorkbook = Workbook.Load(workbookPath2); //workbookPath2 is a .xls file
foreach (Worksheet sheet in ExistingWorkbook.Worksheets)
{
if (sheet.Name.Equals(currentSheet2))
{
for (int i = 1; i <= 204; i++)
{
if (i <= 55)
{
int x = i + 17;
WorksheetRow row = sheet.Rows[x];
row.Cells[4].Value = excel_temp[i.ToString()].ToString();
}

....

ExistingWorkbook.Save(workbookPath2);

Any replies are really appreciated.

Thank you.