本帖最后由 jdwang1000 于 2013-8-30 23:12 编辑
曾于2012/11/11访问过gengsai 的帖子[求助]VBA可以完全卸载加载宏
当时依该帖内容作了部分修改后可以完全卸载加载宏
现将我的作法发表于此希望能提供需要者参考附件内含
1. Install_2003_cn.xls (未加锁可自行参阅程式码)
2. Uninstall_Lunar_03_cn.xls (未加锁可自行参阅程式码)
3. Lunar_24_V1.4_03.dll
4. Lunar_24_V1.4_03.xla
此加载宏档是农历函数加载成功后简介如下 :
本转换函数具有许多参数可供使用
Lunar(Year,Month,Day,Type)
Year --- 年 -5000 ~ 5000 (为了要适用 1900/01/01 以前的日期所以区分为 年 月 日 三项
Month --- 月
Day --- 日
Type --- 输出类型 可省略 (内定为0)
Type = 0 或省略 ( =Lunar(2012,4,20) 或 Lunar(2012,4,20,) 或 Lunar(2012,4,20,0) 三十 )
Type = 1 月日 ( =Lunar(2012,6,14,1) 闰四月(小) 廿五 )
Type = 20 月日国定假日 ( =Lunar(2012,6,23,20) 五月(大) 初五 端午节 )
Type = 21 月日农历节日 ( =Lunar(2012,2,23,21) 二月(小)初二 龙头节 )
. . . . . .. .. . . .. .. .
以下将先列出安装档程式模块内容(Install_2003_cn.xls)
二楼及三楼为卸载加载宏与卸除 dll 作法 - Option Explicit
- Sub DynamicAddin()
- Dim WB, addX, Notice_Str
- Dim strFilename As String
- Dim strAddInName As String, Reg_Str As String
- Dim Re_Install As Boolean
- Dim Install_Num As Byte, Ans As Byte
-
- Notice_Str = Range("F6:H8")
- Re_Install = True
- Install_Num = 0
- On Error GoTo Err_Static
- Do While (Re_Install And Install_Num < 3)
- MsgBox Notice_Str(1, 1) & _
- Chr(10) & Chr(10) & Chr(10) & Space(16) & Notice_Str(1, 2)
- Shell "cmd.exe /c md C:\Lunar_24_V1.4_03"
- Application.Wait (Now + TimeValue("0:00:01"))
- If Not FileExist("C:\Lunar_24_V1.4\Lunar_24_V1.4_03.dll") Then
- Reg_Str = Application.ThisWorkbook.Path & "\Lunar_24_V1.4_03.DLL"
- FileCopy Reg_Str, "C:\Lunar_24_V1.4_03\Lunar_24_V1.4_03.DLL" ' err -- 53
- End If
- Ans = MsgBox(Space(7) & "再次确认是否为系统管理员身分进行安装" & _
- Chr(10) & Chr(10) & Chr(10) & "一般使用者无法有效注册 Lunar_24_V1.4_03.DLL " & _
- Chr(10) & Chr(10) & Chr(10) & Space(24) & "将导致所有安装无效 !! ", 260, "JW 管理员身份确认")
- If Ans = 7 Then
- MsgBox Space(8) & "即将退出 Lunar_24_V1.4_03 安装程序" & _
- Chr(10) & Chr(10) & Chr(10) & Space(4) & "请取得系统管理员身分后再进行此安装 !!"
- Exit Sub
- End If
-
- Reg_Str = "cmd.exe /c regsvr32 /s C:\Lunar_24_V1.4_03\Lunar_24_V1.4_03.DLL"
- Shell Reg_Str
- Application.Wait (Now + TimeValue("0:00:01"))
- If Not FileExist("C:\Lunar_24_V1.4_03\Lunar_24_V1.4_03.xla") Then
- Reg_Str = Application.ThisWorkbook.Path & "\Lunar_24_V1.4_03.xla"
- FileCopy Reg_Str, "C:\Lunar_24_V1.4_03\Lunar_24_V1.4_03.xla" ' err -- 53
- End If
- strAddInName = "Lunar_24_V1.4_03"
- strFilename = "C:\Lunar_24_V1.4_03\Lunar_24_V1.4_03.xla"
- Set addX = AddIns.Add(Filename:=strFilename, CopyFile:=True) ' err -- 1004
- addX.Installed = True ' ' err -- 424
- Install_Num = Install_Num + 1
- If Err = 0 Then Re_Install = False
- Loop
- If addX.Installed Then
- MsgBox Space(44) & Notice_Str(1, 3) & Chr(10) & Chr(10) & Chr(10) & Notice_Str(3, 1)
- For Each WB In Workbooks
- If WB.Name <> ThisWorkbook.Name Then WB.Close True
- Next
- ThisWorkbook.Saved = True
- Excel.Application.Quit
- Exit Sub
- End If
- Err_Static:
- Select Case Err
- Case 53
- MsgBox "Lunar_24_V1.4_03.DLL or Lunar_24_V1.4_03.xla" & _
- Chr(10) & Chr(10) & Chr(10) & _
- "无法复制到 C:\Lunar_24_V1.4_03 文件夹" & _
- Chr(10) & Chr(10) & Chr(10) & _
- "请确认以上二档与本 Install_2003.xls 在同一文件夹内"
- Case 424
- MsgBox "加载宏 Lunar_24_V1.4_03.xla 无法正常安装 !!"
- Case 1004
- MsgBox "加载宏 Lunar_24_V1.4_03.xla 无法正确引用 !!"
- End Select
- End Sub
- Function FileExist(strPath As String) As Boolean
- FileExist = (Dir(strPath, vbNormal + vbHidden + vbReadOnly) <> "")
- End Function
- Function FolderExist(strPath As String) As Boolean
- FolderExist = (Dir(strPath, vbDirectory + vbHidden) <> "")
- End Function
复制代码 2
|