Consulting

Results 1 to 8 of 8

Thread: Using Cocoa API in VBA

  1. #1

    Using Cocoa API in VBA

    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

  2. #2
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    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.

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

  3. #3
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    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

    [vba]result = MacScript(script as string)[/vba]

    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.

    [vba]script = "line 1" & Chr(13) & "line 2"[/vba]

    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!

  4. #4
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    So, y'all are the 3 mac users, then? (hee hee...)
    ~Anne Troy

  5. #5
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    Thousand against three!



    Toughest three we ever met!

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

  6. #6
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    Quote Originally Posted by Dreamboat
    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.)

  7. #7
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    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.

  8. #8
    VBAX Regular
    Joined
    Jan 2006
    Posts
    56
    Location

    Perl bridge to Cocoa

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •