Skip navigation
Currently Being Moderated

Can I call an InDesign script from an Excel Macro

Jul 6, 2012 11:23 AM

I am new to InDesign scripts, but making good progress.

 

I have an InDesign Javascript which works perfectly if I call it from inside InDesign or if I double click on the script, say on the desktop.

 

The data (text) required by the script is prepared within Excel by using an Excel macro.

 

I would love to be able to run the InDesign script  from the Excel macro to save a lot of keystrokes (ie Open InDesign, Open Script Panel, Select Script...etc).

 

I have explored such wonders as Shell, wscript.exe, DoScript... but cannot get it to work.

 

Can anyone supply me with an example of the vital few lines of code / syntax.

 

InDesign 6 , Win 7 Office 2010

 

Thanks.

 
Replies
  • Currently Being Moderated
    Jul 6, 2012 12:51 PM   in reply to gnits999

    Run a Powershell script from the macro using Shell() that launches InDesign and make your InDesign script a startup script.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 1:31 PM   in reply to gnits999

    I can't provide working steps, as I haven't had the urge to start up Windows in years.

     

    Assuming you use VBA, a little internet search on the keywords Excel VBA COM TLB should give you some hints: you first have to load the "Reference" to the InDesign TLB type library file from within your VBA Editor. Now it should be possible to use CreateObject to obtain the equivalent of the InDesign JavaScript "app" instance. Then use DoScript to run your script. Don't forget to specify the language, default for app.doScript() is to assume the same language.

     

    The InDesign Scripting Tutorial also has some steps, search for TLB in

    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/i ndesign/cs55-docs/InDesignScripting/InDesign-ScriptingTutorial.pdf

     

    Dirk

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 7, 2012 1:02 AM   in reply to gnits999

    add a reference to the Windows Script Host, then insert the following in your macro anywhere you're ready to run your javascript

     

    Dim ws As New IWshRuntimeLibrary.WshShell
    ws.Run ("C:\Users\carlos\Documents\Adobe Scripts\yourScript.jsx") 'change to your own path
    

     

    the only issue is, it does not seem to allow spaces...so you have to move your script to another folder where you'll get the security warning.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 7, 2012 3:22 AM   in reply to gnits999

    Word exhibits a curious behavior when I run a VBA script in it that targets InDesign. While it is running, *I can still work with InDesign*! It seems VBA (or likely *any* external script) is running asynchronously. I expect Excel to do the same ...

     

    If you sandwich your script commands between InDesign and Excel, you might find this to be the cause of hangs and other unexpected behavior. For instance, Excel starts a native InDesign script that ought to create a new document. Now before InDesign is ready, the Excel script continues with its next command -- attempting to copy text into this -- not yet existing! -- new file.

     

    You'll have to experiment with what you do in each of the scripts. In my scenario above, you might be able to solve it by having the Excel script create the ID document, for example.

     

    (Oh -- and deleting a file with Javascript is perfectly possible. Hint: the command is *not* called 'delete', because that's an internal Javascript command :)

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 7, 2012 11:31 AM   in reply to gnits999

    congrats, happy to see it worked out good.

     

    to close the ID application, add the following line at the end of your jsx script

     

    app.quit();

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points