补丁: 解决了封装之后无法保存EXCEL的问题. 在EXCEL文件中须有如下代码,原来的代码不完善.特此更正. Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.ScreenUpdating = True Application.DisplayAlerts = False ThisWorkbook.Save '文件存盘 Dim myfile As FileSection '定义变量 Dim exec, xlsc, exen As String '定义变量 增加了一个进程名定义exen Application.Visible = False '隐藏EXCEL主窗口 exec = Worksheets("Temp").Cells(1, 1).Value xlsc = Worksheets("Temp").Cells(2, 1).Value exen = Split(exec, "\")(UBound(Split(exec, "\"))) Open exec For Binary As #1 '打开EXE文件 ReDim myfile.Bytes(1 To EXE_SIZE) Get #1, 1, myfile.Bytes '取得固有文件头 Close #1 '关闭打开的EXE文件 Shell "taskkill /im " & exen & " /f" '强制结束EXE文件 Open exec For Binary As #1 '重新生成新的EXE文件 Put #1, 1, myfile.Bytes ''把原EXE文件文件头写进新的文件头 Open xlsc For Binary As #2 '打开xls临时文件 ReDim myfile.Bytes(1 To FileLen(xlsc)) Get #2, 1, myfile.Bytes Put #1, EXE_SIZE + 1, myfile.Bytes '将xls部分追加进EXE Close #1 Close #2 ActiveWorkbook.ChangeFileAccess xlReadOnly ' 将活动工作簿设为只读,便于执行下面的语句,如不进行此操作,将没法完成 Kill ActiveWorkbook.FullName '删除当前文件,其实是一个临时文件 Application.Quit End Sub
[此贴子已经被作者于2008-4-14 3:30:33编辑过] |