ajwillshire
未讀,2011年7月18日 上午11:11:592011/7/18登入以回覆作者
登入以轉寄訊息
你的權限不足,無法在這個群組刪除訊息
該群組的電子郵件地址為匿名,或你需要檢視成員電子郵件地址的權限才能查看原始貼文
收件者:Excel-DNA
Hi,
I know this has come up in a few other threads already (sometimes
almost as a side topic) but I've had trouble getting it to work with
my application and I'm wondering if I'm doing something wrong.
When my add-in is loaded I've got it to read a text file (as a
licence), decode it, check it's valid and set a global constant to
True or False.
If it's false I want it to show a message and then effectively unload
itself so that the functions are not available to be used.
Here's my code (VB) using what I've picked up from other threads:
---------------------------------------------------------------------------------------------------------------------------
Public Sub AutoOpen() Implements
ExcelDna.Integration.IExcelAddIn.AutoOpen
If LicenceBoolean Then
'MsgBox("Hello - This is correctly licenced", vbOK)
Else
MsgBox("This add-in is not licenced - please contact XXX
for more information.", vbOK)
RemoveMe()
End If
End Sub
Public Sub AutoClose() Implements
ExcelDna.Integration.IExcelAddIn.AutoClose
MsgBox("Goodbye World", vbOK)
End Sub
Private Sub RemoveMe()
Dim myName As String =
DirectCast(XlCall.Excel(XlCall.xlGetName), String)
Dim removeId As Object = XlCall.Excel(XlCall.xlfRegister,
myName, "xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value,
2)
Dim removeResult As Object = XlCall.Excel(XlCall.xlfCall,
removeId)
Dim removeUnregister As Object =
XlCall.Excel(XlCall.xlfUnregister, removeId)
End Sub
---------------------------------------------------------------------------------------------------------------------------
Thanks,
Andrew