另存为工作簿类的方法失败 - Outlook vba
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了另存为工作簿类的方法失败 - Outlook vba相关的知识,希望对你有一定的参考价值。
我试图用xlsx文件格式保存outlook邮件附件文件(单个文件)但在Save as Mehtode of workbook class failed
行下面显示错误wb.saveAs
的代码。需要别人的帮助。
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim objExcel As Object
Dim wb As Object
Dim saveFolder As String, dateFormat As String, fName As String
saveFolder = "D:AshokWorkCapitalCollection"
For Each objAtt In itm.Attachments
sFileName = LCase(objAtt.FileName)
sPathName = saveFolder & sFileName
objAtt.SaveAsFile sPathName
Set objExcel = CreateObject("Excel.Application")
Set wb = objExcel.Workbooks.Open(sPathName)
' error on below line
wb.SaveAs FileName:=Replace(sPathName, ".csv", ".xlsx"), FileFormat:=xlOpenXMLWorkbook
wb.Close SaveChanges:=True
Kill sPathName
objExcel.Quit
Next
End Sub
答案
最后我得到了答案:在工具中添加microsoft excel library
并定义wb as workbook
以上是关于另存为工作簿类的方法失败 - Outlook vba的主要内容,如果未能解决你的问题,请参考以下文章