|
楼主 |
发表于 2010-6-24 09:22
|
显示全部楼层
1、加载宏的升级过程经过改进如下:- Sub update()
- Dim xml6 As Object, bt() As Byte, wt As Long
- Dim txtLine
- Dim FileObj
- Dim TextObj
- Dim FilePath
-
- On Error Resume Next
- Application.StatusBar = "正在检测新版本,请稍后......"
- Kill "d:\ver.txt"
- Kill "d:\Test.exe"
- Set xml6 = CreateObject("Microsoft.XMLHTTP")
- URL = "http://www.xxx.com/ver.txt"
- xml6.Open "GET", URL, False
- xml6.send
- If xml6.Status = 200 Then
- bt = xml6.responseBody
- Open "d:\ver.txt" For Binary As #1
- Put 1, , bt
- Close #1
- '读取TXT文件内容
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set ts = fs.GetFile("d:\ver.txt").OpenAsTextStream(1, 0)
- s = Mid(ts.ReadLine, 4, Len(ts.ReadLine) + 3)
- ts.Close
- '判断版本是否一致
- If VBA.Val(Replace(s, ".", "")) <= VBA.Val(Replace(Version, ".", "")) Then
- Kill "d:\ver.txt"
- MsgBox "已是最新版本,有问题请反馈给作者。", vbInformation, "提示
- Application.StatusBar = False
- Else
- '打开更新内容文件
- Application.StatusBar = "发现更新文件"
- Workbooks.OpenText Filename:="D:\ver.txt", StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
- Tab:=True, Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 2)
- Windows("ver.txt").Activate
- Response = MsgBox("当前使用版本:" & Version & Chr(10) & Chr(10) & "检测到新版本:" & s & _
- Chr(10) & Chr(10) & "更新内容见当前文档说明。" & Chr(10) & Chr(10) & "是否立即升级?", _
- vbYesNo + vbInformation + vbDefaultButton2, "提示")
- Windows("ver.txt").Activate
- ActiveWindow.Close
- Kill "d:\ver.txt"
- If Response = vbYes Then
- Application.StatusBar = "正在下载更新文件,请稍后....."
- Set xml6 = CreateObject("Microsoft.XMLHTTP")
- URL = "http://www.xxx.com/test.exe"
- xml6.Open "GET", URL, False
- xml6.send
- If xml6.Status = 200 Then
- bt = xml6.responseBody
- Open "d:\Test.exe" For Binary As #1
- Put 1, , bt
- Close #1
- MsgBox "请注意保存当前打开的Excel文檔" & Chr(10) & Chr(10) & "点击""确定""后将关闭当前文档", vbInformation, "提示
- '运行升级文件
- Workbooks.Close
- Shell "d:\Test.exe", vbNormalFocus
- Application.Quit
- Else
- MsgBox "外部网络不通,无法检测更新", vbInformation, "提示
- End If
- Else
- Application.StatusBar = False
- Exit Sub
- End If
- Exit Sub
- End If
- Else
- '通过局域网升级
- Application.StatusBar = "网络不通,正尝试通过局域网升级......"
- Set fs = CreateObject("Scripting.FileSystemObject")
- fs.copyfile "\\172.20.123.123\update\ver.txt", "d:\ver.txt"
- '读取TXT文件内容
- 'Set fs = CreateObject("Scripting.FileSystemObject")
- Set ts = fs.GetFile("d:\ver.txt").OpenAsTextStream(1, 0)
- s = Mid(ts.ReadLine, 4, Len(ts.ReadLine) + 1)
- ts.Close
- '判断版本是否一致
- If Replace(s, ".", "") <= Replace(Version, ".", "") Then
- Kill "d:\ver.txt"
- MsgBox "当前版本" & Version & "已是最新版本,有问题请反馈给作者。", vbInformation, "提示
- Application.StatusBar = False
- Else
- '打开更新内容文件
- Application.StatusBar = "发现更新文件"
- Workbooks.OpenText Filename:="D:\ver.txt", StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
- Tab:=True, Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 2)
- Windows("ver.txt").Activate
- Response = MsgBox("当前使用版本:" & Version & Chr(10) & Chr(10) & "检测到新版本:" & s & _
- Chr(10) & Chr(10) & "更新内容见当前文档说明。" & Chr(10) & Chr(10) & "是否立即升级?", _
- vbYesNo + vbInformation + vbDefaultButton2, "提示")
- Windows("ver.txt").Activate
- ActiveWindow.Close
- Kill "d:\ver.txt"
- If Response = vbYes Then
- Application.StatusBar = "正在下载更新文件,请稍后......"
- fs.copyfile "\\172.20.123.123\update\test.exe", "d:\test.exe"
- MsgBox "请注意保存当前打开的Excel文檔" & Chr(10) & Chr(10) & "点击""确定""后将关闭当前文档", vbInformation, "提示
- '运行升级文件
- Workbooks.Close
- Shell "d:\Test.exe", vbNormalFocus
- Application.Quit
- Else
- Application.StatusBar = False
- Exit Sub
- End If
- End If
- Else
- MsgBox "外部网络不通,无法检测更新", vbInformation, "提示
- Exit Sub
- End If
- End Sub
复制代码 2、在加载宏中再设定版本号- Sub ver()
- Version = "3.1.6.0.6.040"
- End Sub
复制代码 3、将加载宏用winrar打包成自解压文件
解压文件注释为- Path=%userprofile%\Application Data\Microsoft\AddIns\
- Setup=EXCEL.EXE
- Overwrite=1
- License=提示
- {
- <center><u><b><font face=楷体_GB2312 color=red size=4> 点击“接受”前请关闭EXCEL</font></b></u></center><BR><p>
- <font size=2>----------------------------------------------------------------------------------------</font><BR>
- <font face=楷体_GB2312 color=blue>版本号:3.1.6.0.1.040</font><BR>
- <P>
- <pre><font face=楷体_GB2312 size=3>1、更新内容请参看更新说明文档
- 2、更新完成后系统会自动开启Excel
- 请勿手工开启,以防升级失败。</font></pre>
- <br>
- <P>
- <font size=2>----------------------------------------------------------------------------------------</font><BR>
- <font face=楷体_GB2312>更新日期:2010年6月10日</font>
- }
复制代码 4、升级说明档案ver.txt文件内容见附件形式
ver.zip
(246 Bytes, 下载次数: 238)
[ 本帖最后由 flydove 于 2010-6-24 09:29 编辑 ] |
|