1,216
社区成员
发帖
与我相关
我的任务
分享
Private Sub mnuEXCEL_Click()
Dim IOFilename As String
Dim str As String
Dim cn1 As New ADODB.Connection
Dim cmd1 As New ADODB.Command
Dim rs1 As New ADODB.Recordset
Dim tmpPwd As String
Dim tmpPwd2 As String
tmpPwd2 = UCase(MD5(txtPassWord.Text))
Debug.Print "导出ecxel密码框 " & tmpPwd2
tmpPwd = sysRead("PASSWORD")
Debug.Print "导入excel密码 " & tmpPwd
If tmpPwd = tmpPwd2 Then
If Dir(txtPatch.Text) <> "" Then '检查文件是否存在
txtPassWord.Text = ""
On Error GoTo errClose
FSO.CopyFile App.Path & "\backup\book.xls", App.Path & "\book.xls", True
On Error GoTo errHandle
cn1.Open JetOLEDB & txtPatch.Text
cmd1.ActiveConnection = cn1
cmd1.CommandType = adCmdText
rs1.CursorLocation = adUseClient
rs1.CursorType = adOpenStatic
rs1.LockType = adLockOptimistic
' str = "select tele_code as 号码,username as 姓名,department as 单位,address as 地址,remark as 备注 from tele"
str = "select tele_code as 号码,username as 姓名,department as 单位,address as 地址,remark as 备注 into [excel 8.0;database=" & App.Path & "\book.xls].号码 from tele"
cmd1.CommandText = str
rs1.Open cmd1
codPatch.DialogTitle = "另存为"
codPatch.CancelError = True
On Error GoTo errexit
codPatch.InitDir = App.Path
codPatch.Filter = "excel文件(*.xls)|*.xls"
codPatch.ShowSave
IOFilename = codPatch.FileName
FSO.CopyFile App.Path & "\book.xls", IOFilename, True
Open App.Path & "\record.log" For Append As #1
Print #1, Format(Date, "YYYY-MM-DD") & " " & Format(Time, "HH:MM:SS") & " 导出excel文件"
Close #1
cn1.Close
Else
MsgBox "数据库不存在请检查路径"
Exit Sub
End If
Else
MsgBox "密码错误!"
Exit Sub
End If
Exit Sub
errClose:
MsgBox "导出失败,请检查是否关闭文件" & App.Path & "\book.xls"
Exit Sub
errHandle:
Open App.Path & "\err.log" For Append As #2
Print #2, Format(Date, "YYYY-MM-DD") & " " & Format(Time, "HH:MM:SS") & " 导出excel失败:错误" & Err.Number & "---" & Err.Description
Close #2
Exit Sub
errexit:
Exit Sub
End Sub