Drag-n-Drop_XLA_Install (VB Script)

M

Mark Ivey

If anyone is interested, I played around with the code and created a VB
Script file that will install an Excel addin.

Here is how it works. Take the code below and save it to a ".vbs" file (what
ever filename you see fit to use). Save this file somewhere convenient (like
your desktop). Now you can take an addin file (".xla" type) and drag-n-drop
it onto this VB Script file and it will install the addin for you.

Please feel free to make improvements to this script and let me know of any
problems. I am totally open to ideas for any improvements. I have not
included any error correction/monitors to this code, but feel free to
improve on it and re-post your ideas/thoughts.

VB Script Code (watch for word wrap issues):

'____________________________________________________________________

Dim fso, myAddinFile
myAddinFile = WScript.arguments.item(0)
Set fso = CreateObject("Scripting.FileSystemObject")
myAddinFileName = fso.GetFileName(myAddinFile)

myAddinPath = fso.GetAbsolutepathname(myAddinFile)

sProcessName = "EXCEL.exe"

sComputer = "."
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

Set oShell = CreateObject("WScript.Shell")

Do
Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = '" & sProcessName & "'")

If colProcessList.Count = 0 Then
' process is not running

Dim oXL
Dim oAddin
Set oXL = CreateObject("Excel.Application")
oXL.Workbooks.Add
Set oAddin = oXL.AddIns.Add(myAddinPath, True)
oAddin.Installed = True
oXL.Quit
Set oXL = Nothing
MsgBox myAddinFileName & " was successfully installed.", vbOKOnly, "Addin
Installation OK"
Exit Do

ElseIf colProcessList.Count <> 0 Then
' process is running

MsgBox "Excel is currently open. Please close Excel and try again.",
vbOKOnly, "MS Excel Is Open"
Exit Do
End If
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top