Workbook workbook = null;
//是否包含VBA代码
bool hasVBA = false;
//打开EXECL
workbook = xlApp.Workbooks.Open(excelFile, Missing.Value, false, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, false, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//判断文件中是否包含VBA代码
if(int.Parse(xlApp.Version) >= 12)
{
//Excel2007(包含)以上版本
hasVBA = workbook.HasVBProject;
}
else
{
//Excel2007以前版本
foreach (VBComponent vbc in workbook.VBProject.VBComponents)
{
if (vbc.CodeModule.CountOfLines > 0)
{
hasVBA = true;
break;
}
}
}