使用vbscript以编程方式将模块添加到xls 2003 [英] programatically add module to xls 2003 using vbscript

查看:70
本文介绍了使用vbscript以编程方式将模块添加到xls 2003的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一部分现在正在工作[ 我发现以下内容似乎挂起了;在VBA中运行时添加/删除模块的部分可以工作 我注意到我被提示出现一个对话框,提示我可以单击此工作簿包含指向其他数据源的链接",然后将其挂起 所以我尝试将第二个参数设置为0,也尝试了2,但仍然挂起 (第二个arg是UpdateLinks,可以在此处找到) >) ]

The first part is now working [ I have the following which just seems to hang; the part that adds/deletes the module works when running in VBA I note that I'm prompted with a dialog saying 'this workbook contains links to other data sources' which I ok to, then it hangs So I tried setting the second argument to 0 and also tried 2 but still it hangs (2nd arg is UpdateLinks as can be found here ) ]

dim objExcel
dim objWorkbook
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(  "H:\M\X\C.xls", 0 , , ,"PASSWORD!" )

Const modpath  = "H:\M\V\"
Const modtest  = "TEST.cls"
Const modname  = "TEST"

On Error Resume Next

Dim vbcomp
Set vbcomp = ActiveWorkbook.VBProject.VBComponents(modname)
objWorkbook.VBProject.VBComponents.Remove vbcomp
objWorkbook.VBProject.VBComponents.Import modpath & modtest

objWorkbook.Save
objWorkbool.Close
set vbcomp = nothing
set objworkbook = nothing
set objExcel = nothing

再次编辑2009年4月14日 我现在还允许工具-宏-安全性-vbproject访问"

edited again 14/04/2009 I have now also allowed the 'tools - macro - security - vbproject access'

脚本现在完成,但是,当尝试打开xls以查看是否进行了更改时,我收到一条消息,通知我该工作表已被用于运行脚本的帐户"锁定;打开只读"/通知

The script now finishes, however, when trying to open the xls to see if the changes have been made, I get a message informing me that the sheet is locked by "account used to run script"; open 'read only'/notify

为什么不能正确释放控制权**?**

Why isn't it releasing control correctly**?**

推荐答案

已编辑的脚本有效.

问题是由于我在工作簿级别而不是VBA项目级别提供了密码.

The problem was caused by the fact that I was supplying the password at the workbook level and not at the VBA project level.

在网络上进行快速搜索后发现,无论如何都无法执行此操作(发送密钥等),因此在手动删除项目上的密码后,问题得以解决

A quick search on the web reveals that it is not possible to do this anyway (sendkeys etc) so after manually removing the password on the project, the problem is solved

这篇关于使用vbscript以编程方式将模块添加到xls 2003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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