PDA

View Full Version : Using Cocoa API in VBA



kei
03-13-2005, 04:09 PM
Hello,
I'm new to Mac Office.
In Windows Office I used VBA and linked system DLLs to do API calls. How should I do this in Mac Office? Are there any resources on the web that teaches people how to do that?

Thanks~

Kei

shades
03-13-2005, 05:42 PM
Welcome to the VBAX Zone, Mac-style!

I think AppleScript is the way to do it (perhaps also Perl and Python - both available in OS X). However, I have not moved in that direction. I will look for resources for you.

Also, maybe BlueCactus has some ideas.

BlueCactus
03-13-2005, 11:35 PM
Hi kei,

I'm not aware of any exact equivalents. But like shades says, you can access AppleScript through Office. This may or may not get you what you need, but will allow you to access Finder, other applications whether they are open or not.

You can run an AppleScript from VBA using

result = MacScript(script as string)

where script can be either a script name (allegedly as I have not tried it), or the script itself contained in a string. Multiline scripts are put together using carriage returns, i.e.

script = "line 1" & Chr(13) & "line 2"

Also, you can run Office or Office VBA from AppleScript, so it goes both ways.

If you've never looked at AppleScript, fish around in the Applications/AppleScript folder. If you open the Script Editor and select Open Dictionary from the menus, you can get a quick idea of what can be accessed, whether it's the Finder, Word, Safari, iTunes or whatever. Also, if you have a recent OS X install disk, I think there might be additional stuff buried in the developer tools. Happy hunting!

Anne Troy
03-29-2005, 01:06 AM
So, y'all are the 3 mac users, then? (hee hee...)

shades
03-29-2005, 07:10 AM
Thousand against three!



Toughest three we ever met! :D ;)

BlueCactus
03-30-2005, 08:46 AM
So, y'all are the 3 mac users, then? (hee hee...)
Cheek. I am NUMBER FOUR, I will have you know! (I'd rather be Number Six, but that's a different story.)

BlueCactus
04-27-2005, 12:51 PM
kei,

If you look at the Excel VBA Help pages, there are occasional vague references to being able to call 'Mac code resources'. See, for example, the blurb on the Declare statement. What it all means is anyone's guess.

mansky
01-09-2006, 07:32 AM
kei,
In case you haven't already found it, the bridge between VB and the Cocoa frameworks is via CamelBones in Perl. CamelBones is an Objective C bridge between Perl and Cocoa. I agree with shades and BlueCamel in starting with Applescript. Depending upon what you are trying to do, Applescript may suffice. If you need full assess to Cocoa, then CamelBones, via Perl, is the way to go.

I've called my Perl routines via Applescript from VB just fine. There is overhead involved, but it does give you access to the full scope of Perl/Cocoa and OSX from within Office.

You can check out CamelBones at Sourceforge:

http://camelbones.sourceforge.net/index.html


Ed