Skip to content

Instantly share code, notes, and snippets.

@Winand
Last active November 14, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Winand/5e34529df029baa87b70b6abd0c51d92 to your computer and use it in GitHub Desktop.
Save Winand/5e34529df029baa87b70b6abd0c51d92 to your computer and use it in GitHub Desktop.
`project_name` determines current AddIn name / https://stackoverflow.com/questions/14918464
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