none
通过程序查看vba项目中的数据 RRS feed

  • 问题

  • 有些excel文件包含vba项目,vba项目设置了密码保护,但是我知道这些密码。

    .我在c#程序中如果访问VBProject中的VBComponents属性的话就会提示我“工程已经被保护,不能进行操作”。

    int componentsCount = workbook.VBProject.VBComponents.Count;
    

    运行到这一句代码的时候,出现异常,

    异常信息:

    未处理 System.Runtime.InteropServices.COMException

      HelpLink=C:\PROGRA~1\COMMON~1\MICROS~1\VBA\VBA6\2052\VbLR6.chm#50289

      Message=该工程已被保护,不能进行操作。

      Source=VBAProject

      ErrorCode=-2146777999

      StackTrace:

           at Microsoft.Vbe.Interop._VBProject.get_VBComponents()

           at ExcelVBATest.frmReadExcelAndVBA.TidyVBAOfExcelFile(String filePath, String password) in C:\Users\Jackie\Desktop\ExcelVBATest\ExcelVBATest\frmReadExcelAndVBA.cs:line 141

           at ExcelVBATest.frmReadExcelAndVBA.btnRead_Click(Object sender, EventArgs e) in C:\Users\Jackie\Desktop\ExcelVBATest\ExcelVBATest\frmReadExcelAndVBA.cs:line 83

           at System.Windows.Forms.Control.OnClick(EventArgs e)

           at System.Windows.Forms.Button.OnClick(EventArgs e)

           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

           at System.Windows.Forms.Control.WndProc(Message& m)

           at System.Windows.Forms.ButtonBase.WndProc(Message& m)

           at System.Windows.Forms.Button.WndProc(Message& m)

           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)

           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

           at System.Windows.Forms.Application.Run(Form mainForm)

           at ExcelVBATest.Program.Main() in C:\Users\Jackie\Desktop\ExcelVBATest\ExcelVBATest\Program.cs:line 18

           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

           at System.Threading.ThreadHelper.ThreadStart()

    所以问题是: 我通过什么属性设置来输入vba项目的密码?

    请大家帮忙解决该问题,谢谢!

    2011年4月2日 4:32

全部回复