Just had my first encounter with VSTO, trying to embed a C# macro in an Excel workbook. I fired up the ol' Visual Studio 2005, created a new "Excel Workbook" project and bumped straight into this:
"Programmatic access to the Microsoft Office Visual Basic for Applications project system could not be enabled. If Microsoft Office Word or Microsoft Excel is running, it can prevent programmatic access from being enabled. Exit Word or Excel before opening or creating your project."
The problem with the above message? I didn't have any Word or Excel process running at all.
A quick google gave me the solution for Office 2003 (thanks go to Harry Miller - MSFT):
- On the Tools menu, point to Macro, and then click Security.
- Click the Trusted Publishers tab.
- Select the check box next to Trust access to Visual Basic Project, and then click OK.
- Close all Office applications and try your project again.
But! I'm using Office 2007 beta. Where on earth is the Tools menu there? Yours truly spent well over 2 minutes digging through the menus and ribbons to give you the following instructions:
- Open Excel 2007.
- Click the Office Button (top-left most button in the window)
- Click the Excel Options button.
- Click Trust Center in the menu on the left.
- Click Trust Center Settings in the window on the right.
- In the new window that opens click Macros in the menu on the left.
- Check the box next to Trust Access to the VBA project object model.
- Click OK.
- Click OK.
- Close all Office applications and try your project again.
Works like a charm, as long as you accept the security implications of allowing Excel and Word programmatic access to the "Microsoft Office Visual Basic for Applications project system" mentioned above.