Melon
Melon

Reputation: 11

open protected excel file with com, but the running excel does not support addins

I need to open the encrypted excel file from code, and the end user can also edit or save the opened file. Then I found a way to handle it by using com:

https://learn.microsoft.com/zh-cn/previous-versions/office/troubleshoot/office-developer/automate-excel-from-c

However, The opened excel application does not support excel addins.

for example: the excel setting like

excel setting 1 excel setting 2

when open excel.exe normally,it's like:

normally open, correct

but when use com to open excel.exe by the code, it's like:

open from code, incorrect

the addins disappear.

Also, if you reconfig addins option, addins appear again. So I think there may have no initialization when excel.exe was started.

Is there any way to start open encrypted excel file by excel.exe from code, and all excel function are fine?

Here is the code with vbs(the link below is c code):

Set oExcel = CreateObject("Excel.Application")
Set oWorkbook = oExcel.Workbooks.Open("C:\Users\melon\Desktop\excel\excel tests\chat&sample exam.xlsm", 0, 0, 5, "76350e01-a0bd-44c6-9e4d-0df382c2d789")
oExcel.Visible = true

Upvotes: 0

Views: 54

Answers (1)

Lundt
Lundt

Reputation: 142

Programs started with COM are started by COM with the slash /a parameter. This means Automation is starting the program so it should load clean.

/a

Starts Word and prevents add-ins and global templates (including the Normal template) from being loaded automatically. The /a switch also locks the setting files.

https://support.microsoft.com/en-us/office/command-line-switches-for-microsoft-office-products-079164cd-4ef5-4178-b235-441737deb3a6

Upvotes: 0

Related Questions