Last active
November 14, 2019 20:30
-
-
Save Winand/5e34529df029baa87b70b6abd0c51d92 to your computer and use it in GitHub Desktop.
`project_name` determines current AddIn name / https://stackoverflow.com/questions/14918464
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function project_id() As Long | |
' Generate project ID (1-1000) to find it in Application.AddIns collection | |
Static unique As Long | |
If unique = 0 Then | |
Randomize | |
unique = Int((1000 - 1 + 1) * Rnd + 1) | |
End If | |
project_id = unique | |
End Function | |
Function project_name() As String | |
Dim i | |
For Each i In Application.AddIns | |
On Error GoTo project_name__next: | |
If i.Loaded Then ' Otherwise add-in will be loaded on Application.Run | |
If project_id = Application.Run(i.Name & "!project_id") Then | |
project_name = i.Name | |
Exit Function | |
End If | |
End If | |
project_name__next: | |
Next i | |
End Function | |
Sub Auto_Open() | |
Debug.Print project_name() | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment