我已经开发了一个自定义的Addin到PowerPoint,我正在努力想出一个如何以简单的方式分发它的解决方案。
我最初的计划是将插件(.ppam)放在一个中央驱动器中并让用户从那里添加它,不幸的是,似乎我不能更新它,即在现有位置保存它的新副本,如果用户已打开它(尽管已将其设置为只读)。这可以通过如下脚本使用Excel Addins来完成。
Sub DeployAddIn()
'Test
Dim strNewName As String
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: To deploy finished/updated add-in to a network
' location as a read only file
Dim strAddinDevelopmentPath As String
Dim strAddinPublicPath As String
'Set development and public paths
strAddinDevelopmentPath = ThisWorkbook.Path & Application.PathSeparator
strAddinPublicPath = "C:\Public Path" & Application.PathSeparator
'Turn off alert regarding overwriting existing files
Application.DisplayAlerts = False
'Save the add-in
With ThisWorkbook
strNewName = Left(.Name, InStrRev(.Name, "-") - 1) & "." & Right(.Name, (Len(.Name) - InStrRev(.Name, ".")))
'Save to ensure work is okay in case of a crash
.Save
'Save read only copy to the network (remove read only property
'save the file and reapply the read only status)
On Error Resume Next
SetAttr strAddinPublicPath & strNewName, vbNormal
On Error GoTo 0
.SaveCopyAs FileName:=strAddinPublicPath & strNewName
SetAttr strAddinPublicPath & strNewName, vbReadOnly
End With
'Resume alerts
Application.DisplayAlerts = True
End Sub
任何人都对如何以聪明的方式分发PowerPoint插件有任何想法?
编辑:更新了解决方案
我最终使用了两部分Addin,因为我无法确定用户是否可以运行EXE / MSI文件。基本上我的构建就像
Const strCentralPath As String = Central path
Sub Auto_Open()
Dim objAddins As AddIns
Dim objAddIn As AddIn
Dim dblCurrentVersion As Double
Dim dblMyVersion As Double
Set objAddins = Application.AddIns
'Check if Addin is already added and loaded.
'If it is, check if version is same as local.
For Each objAddIn In objAddins
If objAddIn.Name = "Name of addin" Then
If objAddIn.Loaded = msoCTrue Then objAddIn.Loaded = msoCTrue
GoTo CheckVersion
End If
Next objAddIn
'If addin is not found add it
Call AddAddin
GoTo ExitLine
'Check version
CheckVersion:
dblCurrentVersion = Version(strCentralPath)
dblMyVersion = Version(local path)
If dblCurrentVersion > dblMyVersion Then
Application.AddIns(Name of addin).Loaded = msoFalse
Call AddAddin 'If version is lower, unload and add the the new one.
End If
ExitLine:
Set objAddins = Nothing
End Sub
Function Version(Path As String) As Double
Dim fso As Object
Dim dblDate As Integer
Set fso = CreateObject("scripting.filesystemobject")
intDate = CDbl(fso.GetFile(Path).DateCreated)
Version = intDate
Set fso = Nothing
End Function
Sub AddAddin()
Dim strAddInLocalPath As String
Dim strAddinCentralPath As String
Dim fso As Object
'Get local path
strAddInLocalPath = local path
Set fso = VBA.CreateObject("scripting.Filesystemobject")
DeleteFile strAddInLocalPath
Call fso.CopyFile(strCentralPath, strAddInLocalPath, True)
SetAttr strAddInLocalPath, vbReadOnly
With Application.AddIns.Add(strAddInLocalPath)
.Loaded = msoCTrue
End With
Set fso = Nothing
End Sub
Sub DeleteFile(ByVal FileToDelete As String)
If FileExists(FileToDelete) Then 'See above
SetAttr FileToDelete, vbNormal
Kill FileToDelete
End If
End Sub
Function FileExists(ByVal FileToTest As String) As Boolean
FileExists = (Dir(FileToTest) <> "")
End Function
答案 0 :(得分:1)
我知道我很快就需要面对同样的问题而且一直在考虑两种选择。首先将加载项构建到MSI安装程序包中,我相信它可以自动管理此更新元素(我正在评估the Advanced Installer solution)。其次,我想知道我是否可以构建一个两个加载项架构,第一个加载架构在没有任何UI的情况下加载,它的唯一目的是从远程位置下载主要的一个。但是,我不认为有一种方法可以确定应用程序加载项的加载顺序(即使它看起来像是字母)。我认为这是你想要做的事情吗?
答案 1 :(得分:1)
我不会尝试让多个用户加载相同的加载项文件。
如果用户可以双击EXE或MSI安装程序,这是分发更新的一种方法。由于提到了Advanced Installer,我将补充一点,它将生成其中一个并且是非常的工具,并得到很好的支持。
另一种方法是使用登录脚本将当前版本的插件从集中位置下载到每个用户的本地计算机。然后它会在用户启动PPT之前在系统上,所以没有冲突。
理论上,您可以安装Add-in A,当它自动运行时,它会查看Add-in B的PPA / PPAM文件的日期,如果有更新的版本“Out There”,则将其复制到本地加载项文件夹。然后,无论哪种方式,需求加载Addin B,它做了真正的工作。我认为,当前一种方法同样适用时,似乎要经历很多麻烦。