Sunday, April 5, 2015

C# Excel VBA Side by Side Open a workbook

The Workbook object has an Open method that opens a workbook. The following samples show how to both open a workbook in edit mode and read-only mode in both Excel VBA and C#.

Excel VBA

Readonly:

Dim strFileName as string
Workbooks.Open(FileName:=strExcelFile, ReadOnly:=True)



Normal mode:

Dim strFileName as string
Workbooks.Open(FileName:=strExcelFile)

C#

Readonly:


Excel.Workbook objWb;
objWb = objExcelApp.Workbooks.Open(Filename: fileName,ReadOnly:true);

Normal mode:

Excel.Workbook objWb;
objWb = objExcelApp.Workbooks.Open(Filename: fileName);





No comments: