/build/static/layout/Breadcrumb_cap_w.png

Can anyone guide me how to package excel addins?

How to package excel addins ?


0 Comments   [ + ] Show comments

Answers (6)

Answer Summary:
Posted by: jagadeish 11 years ago
Red Belt
1

Install Excel Add-In

Option Explicit

On Error Resume Next

Dim ObjWshShell, ProgramFiles, AddInPath
Dim oXL, oAddin

Set ObjWshShell = CreateObject(“WScript.Shell”)
ProgramFiles = ObjWshShell.ExpandEnvironmentStrings(“%ProgramFiles%”)

AddInPath = ProgramFiles & “\MyAppFolder\MyAddIn.xla”

Set oXL = CreateObject(“Excel.Application”)
oXL.Workbooks.Add
Set oAddin = oXL.AddIns.Add(AddInPath, True)
oAddin.Installed = True
oXL.Quit

Set oXL = Nothing
Set oAddin = Nothing
Set ObjWshShell = Nothing

WScript.Quit

 

Uninstall Excel Add-In

Option Explicit

On Error Resume Next

Dim oXL,i
Dim crAddin

Set oXL = CreateObject(“Excel.Application”)
For i = 1 to oXL.Addins.Count
Set crAddin = oXL.Addins.item(i)
If crAddin.Name = “MyAddIn.xla” then
crAddin.Installed = False
End If
Next

oXL.Quit
Set oXL = Nothing
Set crAddin = Nothing

WScript.Quit


Comments:
Posted by: piyushnasa 11 years ago
Red Belt
1

Scripts are already given in this post. Just wanted to add that do proper testing while logging in to test user account after installation and uninstallation as well.

Posted by: anonymous_9363 11 years ago
Red Belt
1

Do a search for posts by Captain Planet. His script for this is a vision to behold.

Posted by: HariPrasath 11 years ago
Senior White Belt
0

If i wanna install more than 1 Addin for my application . Where i need to change in above script ?..Can u please Specify bit more clear  .........


As VBScab comment, i followed Captain planet Posts. Now am little aware of Addins like.


1.Create CA for add-ins selection

Call VBscript from Embdded Code.
Schedule it as Immediate, just before InstallInitialize

CA Name: setAddinProperty

Enter the VBScript to Excute:

'set blnfilterByDirectory to True if you want to install all add-ins in a specific directory (also specify the directory name below)
'set blnfilterByDirectory to False if you want to install every single add-in in the Installer
Dim blnfilterByDirectory : blnfilterByDirectory = True
'***Important - This directory name is case-sensitive!!!
Dim filterDirectory : filterDirectory = "INSTALLDIR"

'*************************************
'*****DO NOT EDIT BELOW THIS LINE
'*************************************

Dim tempFileName : tempFileName = ""
Dim tempComponent : tempComponent = ""
Dim addinList : addinList = ""
Dim tempExtension : tempExtension = ""

'If we're filtering by directory, construct the sql command accordingly
If blnfilterByDirectory Then
sql = "SELECT File.Component_,File.FileName,Component.Directory_ FROM File, Component WHERE File.Component_ = Component.Component AND Component.Directory_ = '" & filterDirectory & "'"
Else
sql = "SELECT File.Component_,File.FileName,Component.Directory_ FROM File, Component WHERE File.Component_ = Component.Component"
End If

'start searching through file table for add-ins (.XLA or .XLL files)
Set fileView= Session.Database.OpenView(sql)
fileView.Execute
Set fileRecord = fileView.Fetch
While Not fileRecord Is Nothing
tempFileName = LCase(fileRecord.StringData(2))
If InStr(tempFileName,"|") Then 'if filename is currently in sfn form, try and retrieve the full file name
tempFileName = Split(tempFileName,"|")(1)
End If
                If InStr(tempFileName,".") Then
tempExtension = Split(tempFileName,".")(1)
End If

If (tempExtension = "xla" Or tempExtension = "xll" Or tempExtension = "xlam") Then 'its an excel addin
'construct list of addins, delimited by commas
addinList = addinList & Session.Property(fileRecord.StringData(3)) & tempFileName & ","
End If
Set fileRecord = fileView.Fetch
Wend

Set fileView = Nothing
Set fileRecord = Nothing

'remove trailing comma
If Len(addinList) > 0 Then
addinList = Left(addinList,Len(addinList)-1)
End If

Property("installAddin") = CStr(addinList)
Property("removeAddin") = CStr(addinList)

'update windows installer session environment and current process with any
'path environment variables found in environment table

Dim tempName : tempName = ""
Dim tempValue : tempValue = "" 
Dim tempEnvPath : tempEnvPath = ""
 

sql = "SELECT Name, Value FROM Environment"
 
Set envView= Session.Database.OpenView(sql)
envView.Execute
Set envRecord = envView.Fetch
While Not envRecord Is Nothing

tempName = envRecord.StringData(1)
tempValue = envRecord.StringData(2)     

If Not Instr(tempName,"!") > 0 Then
'if we're not removing env var on installation         

tempName = replace(tempName,"=","") 
tempName = replace(tempName,"+","")
tempName = replace(tempName,"-","")
tempName = replace(tempName,"*","")

If lcase(tempName) = "path" Then                   
     
        If right(tempValue,3) = "[~]" Then
        'prefix 
        tempValue = replace(tempValue,"[~]","")
        tempEnvPath = returnEnvironmentPath(tempValue) & ";" & Session.Installer.Environment("Path")       
        ElseIf left(tempValue,3) = "[~]" Then
        'suffix
        tempValue = replace(tempValue,"[~]","")
        tempEnvPath =  Session.Installer.Environment("Path") & ";" & returnEnvironmentPath(tempValue)                 
        Else
        'replacement, which 'should' never happen with the path var, but for this we'll set as prefix
        tempEnvPath = returnEnvironmentPath(tempValue) & ";" & Session.Installer.Environment("Path")
        End If
        'replace any double-semis
        tempEnvPath = replace(tempEnvPath,";;",";")
        'set session env path                       
        Session.Installer.Environment("Path") = tempEnvPath           
                                           
        'make the relevant Path env var available to current process (and processes spawned therein)
        Set oShell = CreateObject("WScript.Shell")
                Set oProcessEnv = oShell.Environment("PROCESS")
                oProcessEnv("Path") = tempEnvPath
                Set oProcessEnv = Nothing
                Set oShell = Nothing



End If
End If

Set envRecord = envView.Fetch
Wend

Set envView = Nothing
Set envRecord = Nothing
                 
                   
                   
'Function to return 'proper' path for env var               
Function returnEnvironmentPath(envPath)

Set objRE = New RegExp
With objRE
    .Pattern    = "\[.+\]" 'match anything inside and including square brackets Eg [WindowsVolume]
    .IgnoreCase = True
    .Global    = False  'return one instance
End With

' Test method returns TRUE if a match is found
If objRE.Test(envPath) Then                   

Set objMatch = objRE.Execute(envPath)
strProperty = objMatch.Item(0)
Set objMatch = Nothing
'perform the replacement
strEnvPath = objRE.Replace(envPath, Session.Property(Mid(strProperty,2,Len(strProperty)-2)))
returnEnvironmentPath = strEnvPath
Else
    returnEnvironmentPath = envPath
End If     

Set objRE = Nothing 

End Function
   

2. Create CA for Install Excel Add-In

Call VBscript from Embdded Code.


Schedule it straight after ScheduleReboot, Deferred in a User Context

NOT Installed Or MaintenanceMode="Modify"

CA Name :installAddin

Enter the VBScript to Execute:
Option Explicit

On Error Resume Next

Dim ObjWshShell, ProgramFiles, AddInPath
Dim oXL, oAddin

Set ObjWshShell = CreateObject(“WScript.Shell”)
ProgramFiles = ObjWshShell.ExpandEnvironmentStrings(“%ProgramFiles%”)

AddInPath = ProgramFiles & “\MyAppFolder\MyAddIn.xla”

Set oXL = CreateObject(“Excel.Application”)
oXL.Workbooks.Add
Set oAddin = oXL.AddIns.Add(AddInPath, True)
oAddin.Installed = True
oXL.Quit

Set oXL = Nothing
Set oAddin = Nothing
Set ObjWshShell = Nothing

WScript.Quit


[ If i have Multiple Addins where i need to change ? in above Script]


3.Create CA for Uninstall Excel Add-In..

Schedule it straight after InstallInitialize and make it Deferred in a User Context

REMOVE~="ALL"

CA Name: removeAddin

Enter VBScript to Excute:

Option Explicit

On Error Resume Next

Dim oXL,i
Dim crAddin

Set oXL = CreateObject(“Excel.Application”)
For i = 1 to oXL.Addins.Count
Set crAddin = oXL.Addins.item(i)
If crAddin.Name = “MyAddIn.xla” then
crAddin.Installed = False
End If
Next

oXL.Quit
Set oXL = Nothing
Set crAddin = Nothing

WScript.Quit


[What script i need to use if i need to uninstall multiple Addins ]??


Please correct me If am wrong in above following method


Thanks for Your Reply

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ