Skip to main content
Participating Frequently
June 3, 2008
Question

CreateObject() with ID CS2 broken in Vista (VBA)?

  • June 3, 2008
  • 14 replies
  • 1941 views
I posted earlier under a fairly ambiguous subject, so I am re-trying here--forgive the dual post, please...

but I think I have narrowed it down. It appears to be a problem with InDesign CS2 and Vista. I can't get any application to call CreateObject successfully without an "Out of memory" error on the call: even from the command line using .vbs.

Does ANYONE have any idea what's going on? Or any ideas? Ole, you out there?

Thanks,

jdb
This topic has been closed for replies.

14 replies

Participating Frequently
June 5, 2008
Ole,

I read the posts at the link you provided, and now I am trying to re-register my .tlb file with regtlb.exe, but I keep getting an "Invalid Library name specified". I am running it from the command line with Administrator privileges.

Any ideas?

Thanks,

jdb
Known Participant
June 5, 2008
Hi Joel,

Have you seen this other thread?

http://www.adobeforums.com/webx/.3bbf275d.3c064bf7/12

...might help.

Thanks,

Ole
Participating Frequently
June 4, 2008
Ole,

Where do I get regtlb.exe? I can't find it on my hard drive. Can you send it to me: [joel DOT berry AT hotmail DOT com]? I'll test it if you can get it to me.

Thanks,

jdb
Participating Frequently
June 4, 2008
I'll try that. In the meantime, here's something for you. The following script (saved as test.vbs) actually WORKS from the command prompt "cscript test.vbs":

' BEGIN CODE
Dim WSHShell
Dim myInDesign
Dim myDocument
Dim myMessage

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run """C:\Program Files\Adobe\Adobe InDesign CS2\InDesign.exe""", 0, False

Set myInDesign = CreateObject("InDesign.Application.CS2")

myInDesign.Activate
Set myDocument = myInDesign.Open("C:\Users\Joel\_Template.indd")

set myMessage = new progMessage
myMessage.setMessage(myInDesign.ActiveDocument.name)
myMessage.Display

myInDesign.Quit
Set myInDesign = Nothing

Class progMessage
Private messageText

public sub setMessage(s)
messageText = s
end sub

public sub Display
msgbox "Message: " & messageText
end sub

end class
' END CODE

So, you CAN create classes within vbs (at least those run from the command prompt and from within InDesign) AND it seems to create the InDesign object just fine. Weird. This code snippet may help your diagnosis...

UPDATE:

Now, it's not working from the command line. It IS working from the .vbs script in InDesign. Weird. It's always fun trying to find an error when it occurs inconsistently!

Thanks,

jdb
Known Participant
June 4, 2008
Hi Joel,

Does anything happen when you use regtlb.exe to attempt to register the InDesign .tlb file?

Thanks,

Ole
Participating Frequently
June 4, 2008
I agree. I hope you do find the problem. If I am having trouble with it, then you can be sure others who have moved to Vista are! ;0)

Besides the Ruby script error dump above, check out the following screenshots of my attempts to connect within VB and C# 2005. Maybe they will help guide you in the right direction:

http://www.theretailcoach.net/images/vs_InDesign_error.PNG
http://www.theretailcoach.net/images/vs_InDesign_error2.PNG
http://www.theretailcoach.net/images/vs_InDesign_error3.PNG

Hope these help. For some reason, I can't hit the InDesign scripting engine from ANY language or VBA hosting application outside of InDesign itself...

This is a brand new, fresh install of Vista. Ironically, when I "upgraded" my system from XP to Vista, it worked, but I was having all kinds of other problems (i.e., legacy code messing up operations in Vista, Vista refusing to update itself on occasion, etc.) so I formatted my machine and did a clean install... I installed Office 2007 before I installed Adobe InDesign CS2, but that shouldn't make a difference, as the type library was available in Office 2007 Excel for me to add to my references for that project, so I don't know...

Anyway, good luck. Keep me posted...

Thanks,

jdb
Known Participant
June 4, 2008
Hi Joel,

I *think* there's a way to tell Excel to run its own VBA programs--soemthing like InDesign's DoScript method. It might be that everything you need to do can be done without having to rewrite those functions at all--maybe you can make your InDesign VBScript take care of the only the communication between the applications, while your VBA continues to crunch along in Excel as it always has.

In any case, I want to figure out what the original problem is.

Thanks,

Ole
Participating Frequently
June 4, 2008
Gotcha. I'll try it.

Now, for my next trick:

Inside my Excel VBA code as it is now, I have created two classes/objects (class modules) that I use to control InDesign (each object stores a bunch of information from various spreadsheets so that I can just create objects as needed and call the methods of the objects to control InDesign. i.e., instead of a top-down script, this is much more modular and keeps the code cleaner).

Is there a way to create inline objects in VBScript? That was one of the reasons I was asking about JavaScript/JScript. I need (ideally) to re-create these objects somehow...

jdb
Known Participant
June 4, 2008
Hi Joel,

Why not use a VBScript? You've already got the VBA working in Excel, and converting that to a VBScript should be easy. Even if you write the script in ExtendScript/JavaScript (not JScript), you'll have to use a VBScript to talk to Excel--ExtendScript doesn't know anything about Excel.

Here's a VBScript that does something in Excel.

Set myExcel = CreateObject("Excel.Application")
myExcel.Visible = True
myExcel.Workbooks.Add
myExcel.Cells(1, 1).Value = "Hello World"

If you run this from InDesign's Scripts panel, it should create a new workbook in Excel and add text to the first cell. If it doesn't, we might have some other problem.

Thanks,

Ole
Participating Frequently
June 4, 2008
If I go in and rewrite everything from an InDesign/JScript perspective, I will need to create an object to automate Excel, still, within the application, so I can get info into InDesign.

I may opt to code in JavaScript/JScript this time. Do you know the equivalent way in JavaScript/JScript to create an Excel application automation object like CreateObject() in VBA/VBScript?

i.e., what in JavaScript is equal to myInDesign = CreateObject("InDesign.Application")?

Thanks,

jdb