vba_gpe
Thành viên thường trực
- Tham gia
- 15/12/10
- Bài viết
- 296
- Được thích
- 44
- Nghề nghiệp
- Thất nghiệp
Gửi Anh Tuân.Bạn phải tạo chương trình bên VB6 hoặc ngôn ngữ khác, không phải chạy trong Excel. Làm đúng thứ tự như sau:
1. ExcelApp.Addins('YourAddin").Installed = False
2. Thoát Excel - ExcelApp.Quit.
3. Xóa các entries trong Registry liên quan
4. Mở lại Excel và kiểm tra nếu ExcelApp.Addins('YourAddin") is Nothing thì thông báo "Đã gỡ bỏ add-in thành công."
5. Thoát Excel - ExcelApp.Quit. Thoát chương trình.
Em dùng vb6 có viết cái gở bỏ addin theo trình tự trên. Tham khảo ý kiến anh và mọi người:
Code khởi động:
Mã:
Sub Main()
On Error Resume next
Dim ExcelApp As Excel.Application
ExcelApp.AddIns("CSG").Installed = False
ExcelApp.Quit
'- Xoa addin trong regkey Addin Manager
If RegKeyExists("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Add-in Manager\C:\test_addin.xla") = True Then
RegKeyDelete ("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Add-in Manager\C:\test_addin.xla")
End If
'- Xoa addin trong regkey Option
Dim i As Long
For i = 1 To 10
If RegKeyExists("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options\OPEN5" & i) = True And RegKeyRead("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options\OPEN5" & i) = "C:\test_addin.xla" Then
RegKeyDelete ("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options\OPEN5" & i)
End If
Next
'- Mo lai Excel
ExcelApp.Workbooks.Add
ExcelApp.Visible = False 'khong hien file Excel
If ExcelApp.AddIns("test_addin.xla") Is Nothing Then MsgBox "Da go go Addin thanh cong"
ExcelApp.Quit
End Sub
Mã:
'==========================
'==Reading from the Registry:
'===========================
'reads the value for the registry key i_RegKey
'if the key cannot be found, the return value is ""
Function RegKeyRead(i_RegKey As String) As String
Dim myWS As Object
On Error Resume Next
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'read key from registry
RegKeyRead = myWS.RegRead(i_RegKey)
End Function
'==========================
'==Checking if a Registry key exists:
'===========================
'returns True if the registry key i_RegKey was found
'and False if not
Function RegKeyExists(i_RegKey As String) As Boolean
Dim myWS As Object
On Error GoTo ErrorHandler
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'try to read the registry key
myWS.RegRead i_RegKey
'key was found
RegKeyExists = True
Exit Function
ErrorHandler:
'key was not found
RegKeyExists = False
End Function
'==========================
'==Saving a Registry key:
'===========================
'sets the registry key i_RegKey to the
'value i_Value with type i_Type
'if i_Type is omitted, the value will be saved as string
'if i_RegKey wasn't found, a new registry key will be created
Sub RegKeySave(i_RegKey As String, _
i_Value As String, _
Optional i_Type As String = "REG_SZ")
Dim myWS As Object
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'write registry key
myWS.RegWrite i_RegKey, i_Value, i_Type
End Sub
'==========================
'==Deleting a key from the Registry:
'===========================
'deletes i_RegKey from the registry
'returns True if the deletion was successful,
'and False if not (the key couldn't be found)
Function RegKeyDelete(i_RegKey As String) As Boolean
Dim myWS As Object
On Error GoTo ErrorHandler
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'delete registry key
myWS.RegDelete i_RegKey
'deletion was successful
RegKeyDelete = True
Exit Function
ErrorHandler:
'deletion wasn't successful
RegKeyDelete = False
End Function
Em có gửi file đính kèm.
Mong nhận được góp ý của mọi người
Trân trọng
File đính kèm
Lần chỉnh sửa cuối: