rivate Const EXE_SIZE = 180224 '此处数字为前面第7步得到的EXE文件字节数 Private Type FileSection Bytes() As Byte End Type '在Workbook_BeforeClose事件中加入如下代码(对原有的代码可保留): Private Sub Workbook_BeforeClose(Cancel As Boolean) ThisWorkbook.Close True 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 楼主,为什么我在设置excel的时候,这行代码出错了,而且提示错误75,路径/文件访问错误啊? |