Excel 2003-对Visual Basic Project的编程访问不受信任 [英] Excel 2003 - Programmatic access to Visual Basic Project is not trusted

查看:367
本文介绍了Excel 2003-对Visual Basic Project的编程访问不受信任的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试使用C#从Excel工作簿中获取所有VBA代码.

这是一个代码段:

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;// <-- error occurs here




当我尝试使用var oModule = xlsWorkBook.VBProject;
我收到一个com异常,并被告知不信任对Visual Basic Project的编程访问".

我已经在工具->下打开了Excel电子表格.宏_>安全性,受信任的发布者,并选中了对Visual Basic的信任访问"项目.这没有帮助.实际上,一旦我运行该程序,它似乎就会取消自身检查.

我不知道它是否有任何区别,但是我的Microsoft Excel对象参考是11.5,而不是我使用的教程中的12.0.

任何帮助都将被沉淀::doh:




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:

推荐答案

可能有一个可以修改的注册表项.否则,您将在不应用SP3和SP2的情况下使用Excel.
There might be a registry key that you can modify. Otherwise, you''d use Excel without applying SP3 and possibly SP2.


这篇关于Excel 2003-对Visual Basic Project的编程访问不受信任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆