Programmatically set DLL search path in VBA macro

The problem

  • I have a word template which uses VBA’s Declare statement to link to a dll, whose path can be determined within the VBA macro
  • I want to delploy this to the users %APPDATA%\Microsoft\Word\STARTUP directory
  • I DON’T want to permanently change the user’s PATH environment variable (temporarily would be OK, but this doesn’t seem to work as they don’t get refreshed until application restart)

Attempted solution

I tried dynamically adding the code with the Declare statements using ThisDocument.VBProject.CodeModule.AddFromString(code) which works when loading the template from a normal directory, but when the template is within Word\STARTUP, it gives the following error:

Run-time error ‘50289’:

Can’t perform operation since the
project is protected.

And setting the registry key “HKEY___LOCAL_MACHINE\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM” to 1 doesn’t fix this when the template is in Word\STARTUP


I’m really struggling to find a solution. If anyone knows a way to do this, that would be great.

Get the title of the current active Window/Document in Mac OS X

Refering to a previously asked question, I would like to know how to get the title of the current active document.

I tried the script mention in the answers to the question above. This works, but only gives me the name of the application. For example, I am writing this question: When I fire up the script it gives me the name of the application, i.e. “Firefox”. This is pretty neat, but does not really help. I would rather like to capture the title of my current active document. See the image.

Firefox title http://img.skitch.com/20090126-nq2egknhjr928d1s74i9xixckf.jpg

I am using Leopard, so no backward compatibility needed. Also I am using Python’s Appkit to gain access to the NSWorkspace class, but if you tell me the Objective-C code, I could figure out the translation to Python.


Ok, I’ve got a solution which is not very satisfing, thats why I don’t mark Koen Bok’s answer. At least not yet.

tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
if the (count of windows) is not 0 then
    set window_name to name of front window
end if
end tell

Save as script and invoke it with osascript from the shell.