|
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.ReadOnly = True Then
ThisWorkbook.Close SaveChanges:=False
Else
ThisWorkbook.Close SaveChanges:=True
End If
Dim myfile As FileSection '定义变量
Dim comc, exec, xlsc As String '定义变量
Application.Visible = False '隐藏EXCEL主窗口
exec = Worksheets("temp").Cells(1, 1).Value
xlsc = Worksheets("temp").Cells(2, 1).Value
comc = exec & " " & xlsc
Open exec For Binary As #1 '打开EXE文件
ReDim myfile.Bytes(1 To EXE_SIZE)
Get #1, 1, myfile.Bytes '取得固有文件头
Close #1
If VBA.Dir(exec) <> "" Then Kill exec
Open exec For Binary As #1 '生成新的EXE文件
Put #1, 1, myfile.Bytes '先写入文件头
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
Application.Quit
Shell comc, vbMinimizedNoFocus '删除临时xls文件
End Sub
If ThisWorkbook.ReadOnly = True Then
ThisWorkbook.Close SaveChanges:=False
Else
ThisWorkbook.Close SaveChanges:=True
End If
这段代码为何不起作用,封装后这段代码不起作用,如果是非只读状态打开,文件自动保存。
请问各位要如何修改呢。 |
|