您的位置:首页 > 编程语言 > VB

关于以前写的VBA在新版本64位Inventor中无法使用的问题

2010-05-21 16:04 579 查看
问题:以前使用的VBA程序,使用了诸如ThisDocument、Me这样的对象,在新版的Inventor 64位里面,无法使用了。(现在需要使用ThisDocument.InventorDocument这样的表述方法),并且由于使用了Autoopen这样的自动执行的函数,导致打开一个Inventor部件的时候,弹出大量的错误对话框。能否将Inventor里面的VBA功能禁用,或者禁用AutoOpen函数?能否批量的将零件文件中的VBA程序代码删除或改写,这种操作是可以脱离Inventor进程进行,还是必须在Inventor中进行?



解决方法:

一、按住shift健就可以禁用Auto宏命令,Inventor API帮助文档里有说明:

"Autodesk Inventor runs automatic macros automatically whenever the associated events occur. If the user presses the Shift key when the event occurs, the automatic macro
will not run. For example, if the user presses the Shift key while opening a document that contains an AutoOpen macro, the macro will not run."

二、要删除或者修改VBA程序,有两种方法:

可以编写VBA项目(.ivb文件)或者一个简单的宏命令来删除文件中的VBA程序(等用户打开了文件后执行该命令)。例子如下:

'You need to set a reference to the Microsoft Visual Basic for Applications 

'Extensibility library, Tools > References 

Sub test() 

Dim l_mod As InventorVBAComponent ' VBComponent 

Dim l_project As InventorVBAProject 

For Each l_project In ThisApplication.VBAProjects 

If l_project.ProjectType = kDocumentVBAProject Then 

For Each l_mod In l_project.InventorVBAComponents 

'ThisDocument module can't be deleted, so if Thisdocument, delete code of lines 

If l_mod.Name <> "ThisDocument" Then 

l_mod.VBComponent.Activate 

l_project.VBProject.VBComponents.Remove l_mod 

Else 

l_mod.VBComponent.CodeModule.DeleteLines 1, l_mod.VBComponent.CodeModule.CountOfLines 

End If 

Next 

End If 

Next 

End Sub


注:需要增加Microsoft Visual Basic for Applications Extensibility library (工具 -> 参考...)。 CodeModule还有一个ReplaceLine函数可以修改VBA代码。

你也可以做个插件实现上述代码,再做个菜单方便界面调用。插件的一个好处是它可以有安装程序,所以不用配置/修改用户机器上的默认的.ivb文件(应用程序项目),也不用你手动的去加载你的VBA项目。

以上两种方法都离不开Inventor进程。

三,这种方法可以脱离Inventor,请看我的另外一篇文章:免费的删除文档中的VBA程序的工具及源码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐