Hi all,
I am trying to use C# to get all the VBA code from an Excel work book.
Here is a code snippet:
Excel.Workbooks xlsWorkbooks;
Excel.Workbook xlsWorkBook;
Excel.Worksheet xlsWorkSheet;
VBIDE.VBE vbEditor;
VBIDE.VBProject vbProject;
var xlsApplication = new Excel.Application();
var path = @"C:\VBATest.xls";
xlsWorkBook = xlsApplication.Workbooks.Open(path, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
var oModule = xlsWorkBook.VBProject;
When I try to use
var oModule = xlsWorkBook.VBProject;
I get a com exception and am told 'Programmatic access to Visual Basic Project is not trusted'.
I have opened the excel spreadsheet, under tools -> macro _> security, trusted publishers, and checked the 'Trust access to Visual Basic' project. This has not helped. In fact, it seems to un-check itself once I run the program.
I don't know if it makes any difference, but my Microsoft Excel Object Reference is 11.5 and not 12.0 as on the tutorial I was using.
Any help would be precipitated :doh: