1

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.

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

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).

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.

EDIT:

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?

10
  • in your script I do not see you define cdrPNG. Is this a enumeration from Coral Draw? Commented Nov 15, 2013 at 16:00
  • Yes, it is. I copied the code that was generated when I recored a macro in Corel DRAW... Commented Nov 15, 2013 at 16:01
  • 1
    I fear that you have not choice than defining them yourself by Const cdrPNG= "My Constant Value" or Const cdrPNG = MyNumericValue on the head of your VBScript. Commented Nov 15, 2013 at 16:03
  • you need to reference CoralDraw in order for it to know the association. drawApp.Application.crdPNG <-- not sure if that is the correct path to the enum as I do not have CoralDraw ont his machine. Take a look at this doc for some info that may help. apps.corel.com/partners_developers/csp/resources/dvba_pg.pdf Commented Nov 15, 2013 at 16:07
  • 1
    @AnsgarWiechers Yes I'm aware it's not VBScript, already mentioned as "script package". It's just a way like "adding constants manually". "adding constants manually" is not VBScript also, is not it? I asked because I care about your opinion. And I got the answer. I think :/ Commented Nov 15, 2013 at 22:32

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.