0
votes

Currently I try to write a service (run by system account) that creates macro in an Excel workbook. It seems that I can open excel, create a new workbook, add data and markup to it, but when I try to add a macro to the excel, I get a security message:

"Programmatic access to Visual Basic Project is not trusted"

I do have "Trust access to vba project object medal" turned on. However, is it possible that this setting is user-dependent instead of machine dependent? Is there a way to let my C# service have access to the macros of the excel workbooks it creates (at time of creation...)

thanx!!!

Best regards,

Jan

1
I can't verify this at the moment, otherwise I would put it into an answer, but I am pretty sure that the security settings for Excel (or Office applications in general) are user specific. So you would have to change it for all users on a specific machine, and if a new user logs in, you'll need to change it for them.psubsee2003

1 Answers

0
votes

psubsee2003, thx for the reaction...

In the end I solved the problem like this:

The excel file:

  • I created an excel file that has no data in it and one macro
  • The macro runs only when there is data in the sheet (if cell x = empty then exit sub)
  • The macro sets print ranges correct

The service:

  • Service opens the excel file
  • Adds the data
  • Service saves a copy of the original file (meaning the original file stays untouched)