我已打开Excel文件并将Excel内容复制到Outlook以发送邮件。 所有这些功能都有效。 但是,当我想关闭Excel并删除Excel文件时,操作失败。它显示错误代码
许可被拒绝
显然Excel文件仍然打开。
任何人都可以帮忙调试吗?
代码如下所示:
Set outlook = CreateObject("Outlook.Application")
Set email = outlook.CreateItem(0)
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook =objExcel.Workbooks.Open("W:\d\PCCW\realtime_MTR\PUCCH_level.xlsx")
Set objWorksheet = objWorkbook.Worksheets("PUCCH")
Dim sRangeValues
LastRow = objWorksheet.UsedRange.Rows(objWorksheet.UsedRange.Rows.Count).Row
Set r = objWorksheet.Range("A1:G" & LastRow)
objWorksheet.Activate
For i = 2 To r.Rows.Count
For j = 1 To r.Rows(i).Columns.Count
sRangeValues = sRangeValues & r.Rows(i).Columns(j).Value & " | "
Next
sRangeValues = sRangeValues & "<br>"
Next
With email
'.to="edwincheng@hk.chinamobile.com;"
.To = "edwincheng@hk.chinamobile.com;"
.Subject = "Houly MTR Alerter"
.HTMLBody = "PUCCH:<br>" & "Date |Time |eNodeB|Plan_Site_Name|Cell Name|PUCCH(dBm)| <br>" & sRangeValues & "<br>"
.Send
End With
WScript.Quit
objWorkbook.Save
objWorkbook.Close (False)
objExcel.Quit
Set obj1 = CreateObject("Scripting.FileSystemObject")
obj1.DeleteFile("W:\d\PCCW\realtime_MTR\PUCCH_level.xlsx")