powerpoint addin如何获得自己的名字?

时间:2013-02-17 06:06:01

标签: vba add-in powerpoint

我有一个名为“abcde.ppam”的PowerPoint插件文件。 我还添加了一个“Auto_Open”Sub,以便在PowerPoint Application启动时运行一些代码。 我的问题是如何在“Auto_Open”中获得名称“abcde.ppam”? 有什么像“ThisAddin.name”或“ThisAddin.path”或其他任何解决方法吗?

3 个答案:

答案 0 :(得分:0)

您需要做的就是在加载项的代码中声明一个字符串常量,并将其设置为加载项的名称。

然后你可以做Application.Addins(MyName).Path等等

答案 1 :(得分:0)

史蒂夫,我必须纠正你。您可以通过调用构建到插件中的唯一函数来识别插件。如果它存在,即使用户可能已重命名该文件,您也知道这是非常的插件。大致

sub getMe()
dim MyAddin as addin
dim oAddin as addin
for each oAddin in application.addins
on error resume next
if (application.run ....uniqueFunction) = "YepItsMe" then
 Set MyAddin = oAddin
 exit for
end if
err.clear
next

'....code acting upon MyAddin

end sub

function uniqueFunction() as string
uniqueFunction="YepItsMe"
end function

答案 2 :(得分:0)

好的,这个方法怎么样。您想要将WhoAmIToday重命名为每个加载项唯一的名称。 WhoMe_ {guid}等。

Sub Auto_Open()

    Dim x As Long
    Dim sTemp As String
    Dim sFilename As String

    ' Get the internal name of the add-in
    sTemp = WhoAmIToday

    For x = 1 To Application.AddIns.Count
        On Error Resume Next
        ' Attempt to call the same WhoAmI routine on each addin in the addins collection
        If Application.Run(Application.AddIns(x).Name & "!WhoAmIToday") = sTemp Then
            If Err.Number = 0 Then
                ' Found it; here's the name
                MsgBox Application.AddIns(x).Name
            End If
        End If

    Next

End Sub

Function WhoAmIToday() As String
   WhoAmIToday = "Yes. It's ME"
End Function
相关问题