0

我有一个名为“abcde.ppam”的 PowerPoint 插件文件。而且我还添加了一个“Auto_Open”子,以便在 PowerPoint 应用程序启动时运行一些代码。我的问题是如何在“Auto_Open”中获得名称“abcde.ppam”?是否有“ThisAddin.name”或“ThisAddin.path”之类的东西或任何其他解决方法?

4

3 回答 3

1

好的,这个方法怎么样。您希望将 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
于 2017-03-09T17:15:47.807 回答
0

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

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

于 2013-02-19T00:14:45.377 回答
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
于 2014-12-16T10:01:38.890 回答