|
楼主 |
发表于 2011-9-8 12:51
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
添加新功能:
本帖最后由 baomaboy 于 2011-9-24 13:03 编辑
用途:
VB代码精简去冗余,用于封装发布前减小文件体积。(缩进排版的反方向)
用法:
1.由网页或者VBE编辑等复制源码到剪贴板中。
2.点击Excle菜单→格式→代码精简优化(或者使用快捷键:Ctrl+Alt+Shift+T)。
3.剪贴板中已经是精简去冗余后的代码了。
4.附件在1楼更新。
谢谢 xtanuihazfh 的花
'---------------------精简去冗余之前的代码--------------
代码: | Dim RegDll As Long, UnRegDll As Long
Const AppVer As String = "Excel加载项管理器 V1.05"
Private Sub Form_Load() '窗体载入,程序初始化。
On Error Resume Next
If App.PrevInstance Then
'MsgBox "你已经运行这个应用程序了"
Unload Me
End
Exit Sub
End If
'------------------初始化安装窗口信息
'Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3) '设置窗体在前'此句需要注释掉,因为展开注册表时会由于此句存在而被置后显示。
Me.Top = (Screen.Height - Me.Height) / 2 '设置窗体上下居中
Me.Left = (Screen.Width - Me.Width) / 2 '设置窗体左右居中
Me.Caption = AppVer
Frame2.Caption = "关于本程序"
Label1.Caption = vbCr & AppVer
Label2.Caption = vbCr & AppVer & vbCr & vbCr & vbCr & vbCr & " by baomaboy"
Text1 = ""
AppPath = App.Path: If Right(AppPath, 1) = "\" Then AppPath = Left(AppPath, Len(AppPath) - 1) '取得应用程序自身路径由于xp和2003返回路径最后包含“\”是不一样的,所以统一去掉尾部“\”
InsDllPath = GetWinDir: If InStr(UCase(InsDllPath), "SYSTEM") = 0 Then InsDllPath = Split(Environ("Path"), ";")(0): If InStr(UCase(InsDllPath), "SYSTEM") = 0 Then InsDllPath = FSO.GetSpecialFolder(1) '备用两种去系统路径的方法
ExVer = Left(GetVer(GetExPath), 4)
IsOld = True '设置读取已安装宏的标记
Call GetList '读取注册表中的加载宏列表
bdmoban = "norma1/results/book1/rpt_pdm2cvs/startup"'病毒生成的模板名
bdsheet = "(m1)_(m2)_(m3)/xl4poppy/startup/00000ppy"'病毒生成的表格名
bdstring = Split(bdmoban & "/" & bdsheet, "/")
Command2.Enabled = False: Command3.Enabled = False: Command4.Enabled = True: Command5.Enabled = True: Command6.Enabled = False: Command7.Enabled = False: Command8.Enabled = False: Command10.Enabled = False
Call IsBDJK '开启病毒监控的杀毒程序
End Sub
|
'---------------------精简去冗余之后的代码--------------代码: | Dim RegDll As Long, UnRegDll As Long
Private Sub Form_Load()
On Error Resume Next
If App.PrevInstance Then
Unload Me
End
Exit Sub
End If
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
Me.Caption = AppVer
Frame2.Caption = "关于本程序"
Label1.Caption = vbCr & AppVer
Label2.Caption = vbCr & AppVer & vbCr & vbCr & vbCr & vbCr & " by baomaboy"
Text1 = ""
AppPath = App.Path: If Right(AppPath, 1) = "\" Then AppPath = Left(AppPath, Len(AppPath) - 1)
InsDllPath = GetWinDir: If InStr(UCase(InsDllPath), "SYSTEM") = 0 Then InsDllPath = Split(Environ("Path"), ";")(0): If InStr(UCase(InsDllPath), "SYSTEM") = 0 Then InsDllPath = FSO.GetSpecialFolder(1)
ExVer = Left(GetVer(GetExPath), 4)
IsOld = True
Call GetList
bdmoban = "norma1/results/book1/rpt_pdm2cvs/startup"
bdsheet = "(m1)_(m2)_(m3)/xl4poppy/startup/00000ppy"
bdstring = Split(bdmoban & "/" & bdsheet, "/")
Command2.Enabled = False: Command3.Enabled = False: Command4.Enabled = True: Command5.Enabled = True: Command6.Enabled = False: Command7.Enabled = False: Command8.Enabled = False: Command10.Enabled = False
Call IsBDJK
End Sub
|
|
|