2013-02-17 21 views
0

我有一個名爲「abcde.ppam」的PowerPoint插件文件。 而且我還添加了一個「Auto_Open」Sub以便在PowerPoint應用程序啓動時運行一些代碼。 我的問題是如何獲得「Auto_Open」中的名稱「abcde.ppam」? 是否有像「ThisAddin.name」或「ThisAddin.path」或其他解決方法?powerpoint插件如何獲得自己的名字?

回答

0

您只需要在加載項的代碼中聲明一個字符串常量並將其設置爲加載項的名稱即可。

然後,你可以做Application.Addins(MYNAME)。路徑等

+0

謝謝你回答這個問題。不過我想要的是Addin本身的名字。如果我已經知道插件的名稱是「MyName」,我不需要其他任何東西。 – kagen88 2013-02-22 06:05:57

+0

我不明白他們的問題。當你寫它時,你肯定知道加載項的名字。按照我的建議將名稱分配給常量,並且加載項將知道其自己的名稱。 – 2013-02-23 16:46:40

+0

只想知道Addin在不知道名稱的情況下如何引用自身? – kagen88 2013-02-26 08:15:49

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 
+0

如何更改'oAddin'影響行if(application.run .... uniqueFunction)=「YepItsMe」then'? – Degustaf 2014-12-16 15:22:53

+0

加載項可能知道「uniqueFunction」的值,但它不會知道它的實際名稱或路徑。你的代碼會將'myAddIn'設置爲列表中的第一個加載項,而不是實際的加載項。 – 2017-03-08 20:26:09

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 
相關問題