Automatically Detect MS Office Install Location

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

Automatically Detect MS Office Install Location

Post by ueberyak » Tue Jul 19, 2016 4:41 pm

I am working on a script which needs to run an MS Access macro. Typically I do this with RunProgram> as ExecuteFile doesn't have a macro argument.

My issue is that I won't know which version of MS Office the user will have. I guess I could look for MSACCESS.EXE in multiple folders, but it's harder than I anticipated finding a complete list of installation folders for both 64 bit and 32 bit.

Is there a way I can identify the installation location for Access programatically?
Thanks,
Josh

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1380
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Automatically Detect MS Office Install Location

Post by Dorian (MJT support) » Fri Jul 22, 2016 11:34 pm

How about something like this? Using DOS seems to work pretty well, and running this only took a second or so.


  View Snippet Page
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Automatically Detect MS Office Install Location

Post by Grovkillen » Sat Jul 23, 2016 5:20 pm

Can't you do it by checking the registry?

https://support.microsoft.com/en-us/kb/240794
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Automatically Detect MS Office Install Location

Post by Marcus Tettmar » Thu Aug 04, 2016 4:46 pm

ueberyak wrote:I am working on a script which needs to run an MS Access macro. Typically I do this with RunProgram> as ExecuteFile doesn't have a macro argument.
ExecuteFile DOES let you pass parameters - see help file:
https://www.mjtnet.com/manual/executefile.htm

"ExecuteFile>file_to_execute[,parameters]"

So you can simply do this:

Code: Select all

ExecuteFile>%USERDOCUMENTS_DIR%\MyDb.accdb,/x Macro1
This will open the DB and run macro "Macro1". Note my DB is in my documents folder here so I'm just using USERDOCUMENTRS_DIR but this could be any path.

Another way would be to use VBScript:

Code: Select all

VBSTART
  Sub RunMacro(accessfile,macroname)
    dim accessApp
    set accessApp = createObject("Access.Application")
    accessApp.OpenCurrentDataBase(accessfile)
    'comment next line out if you don't want access to be visible
    accessApp.visible = true
    accessApp.DoCmd.RunMacro macroname
    'you can run a subroutine or function in module code instead if you want:
    'accessApp.run "routinename"
    accessApp.Quit
    set accessApp = nothing
  End Sub
VBEND

VBRun>RunMacro,%USERDOCUMENTS_DIR%\MyDb.accdb,Macro1
This gives you more control - you could make it invisible, and as you can see you could run VBA code instead if you want - or access any of the other methods. Anything you can do inside Access you can do here - converting VBA to VBScript:

http://help.mjtnet.com/article/19-conve ... o-vbscript

But if you do want to get the path, how about query the mime-type in the registry:

Code: Select all

RegistryReadKey>HKEY_CLASSES_ROOT,ms-access\shell\open\command,,accPath
ExtractFilePath>accPath,accPath
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts