VBScript和VBA-名称空间问题 [英] VBScript and VBA - namespace issues

查看:128
本文介绍了VBScript和VBA-名称空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用VBA自动执行一些步骤,并且还希望能够从命令行执行所有操作.在我的示例中,我使用的是Corel Draw,但我认为我的问题与Corel Draw无关-它更多地是关于名称空间的问题.

I want to automate some steps using VBA, and I also want to be able to execute everything from the command line. In my example I'm using Corel Draw, but I think that my question is independent from Corel Draw - its more a question about namespaces.

所以我写了以下小脚本(称为foo.vbs):

So I wrote the following small script (called foo.vbs):

dim drawApp
Set drawApp = CreateObject( "CorelDraw.Application.14" )
drawApp.OpenDocument( "C:\foo\bar.cdr" )

Dim exportFilter
set exportFilter = drawApp.ActiveDocument.ExportBitmap("bar.png", cdrPNG, cdrAllPages, cdrRGBColorImage, 10206, 8578, 300, 300, cdrNormalAntiAliasing, False, False, True, False, cdrCompressionNone)

然后,我从命令行运行它:

Then, I run it from the command line:

cscript.exe foo.vbs

我收到未定义cdrPNG的错误.当然-我没有在VBScript中包含任何Corel Draw特定内容.但是,如何添加特定于一个应用程序的VBA内容? (这也可能使我能够编写dim drawApp as CorelDRAW.Application之类的东西.)

I get the error that cdrPNG is not defined. Of course - I did not include any Corel Draw specific stuff into the VBScript. But how do I incluce VBA stuff that is specific for one application? (This might also enable me to write dim drawApp as CorelDRAW.Application or something like that).

我是VBA和VBScripts的新手,但是我找不到很好的教程或参考资源(Microsoft网站不是很有帮助).任何指针都欢迎.

I'm very new to VBA and VBScripts and I have not been able to find good tutorials or reference resources (the Microsoft site is not very helpful). Any pointers welcome.

我复制了我在Corel Draw中重新定义宏时生成的代码中的ExportBitmap部分.从重新编码的宏中学习代码似乎是了解该软件的VBA功能的好方法.有更好的方法吗?

I copied the ExportBitmap-part from the code that was generated when I recored a macro in Corel Draw. Studying code from recored macros seems a nice way to get to know the VBA capabilities of the software. Is there a better way?

推荐答案

如果您考虑使用.wsf脚本包而不是.vbs脚本文件,那么一切对您来说都会更加容易.添加 WSF文件支持的类型库

If you considered to use a .wsf script package instead .vbs script file, everything would be easier for you. Adding type libraries supported in WSF files.

<package>
    <job id="Main">
        <!-- 
        add type library reference specifying progid and version
        then all enum constants will be ready to use
        -->
        <reference object="CorelDraw.Application" version="14.0" />
        <script language="VBScript">
            Option Explicit

            Dim drawApp
            Set drawApp = CreateObject("CorelDraw.Application.14")
                drawApp.OpenDocument("C:\foo\bar.cdr")

            Dim exportFilter
            Set exportFilter = drawApp.ActiveDocument.ExportBitmap( _ 
            "C:\foo\bar.png", cdrPNG, cdrAllPages, cdrRGBColorImage, 10206, 8578, 300, 300, _ 
            cdrNormalAntiAliasing, False, False, True, False, cdrCompressionNone, Nothing, Nothing)
                exportFilter.Finish
                drawApp.Quit
        </script>
    </job>
</package>

这篇关于VBScript和VBA-名称空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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