将Excel附件保存为.txt – 使用Outlook 2010中的vbamacros打开

我有Outlook中的VBA代码下载Excel附件的特定电子邮件。 一旦保存,我打开Excel文件,并改变了一些东西,然后我想保存为.txt而不是Excel。

这是我的代码:

' Save the attachment as a file. objAttachments.Item(i).SaveAsFile strFile 'Open the attachment file Set xlApp = CreateObject("Excel.Application") xlApp.Workbooks.Open (strFile) xlApp.Visible = True xlApp.Workbooks.Item(1).activesheet.cells(1, 1).Value = "whatever" **xlApp.SaveAs strFile, FileFormat:=xlText** xlApp.Workbooks.Close 

有谁知道如何将Excel保存在Outlook的VBA中?


对不起,如果没有我想要的那么清楚。

不工作的部分是:

xlApp.SaveAs strFile,FileFormat:= xlText

我从Outlook 2010运行这个,我不明白为什么不工作,当我试图保存为纯文本的Excel(机智制表符分隔),我做错了什么?

谢谢你的回应。

这将把它保存为csv。 我不知道你真的想要一个纯文本文件,因为你会失去所有的列结构..

 ActiveWorkbook.SaveAs filename:="C:\Temp\" & ActiveSheet.name & ".csv", FileFormat:=xlCSV 

这是我在某些时候写出的一个函数来导出整个工作簿。 它将每个工作表放到它自己的文本文件中。

 Sub SaveWorksheetsAsCsv() Dim ws As Excel.Worksheet Dim SaveToDirectory As String Dim CurrentWorkbook As String Dim CurrentFormat As Long Dim cell As Range CurrentWorkbook = ThisWorkbook.FullName CurrentFormat = ThisWorkbook.FileFormat ' Store current details for the workbook SaveToDirectory = "C:\Temp\" For Each ws In ThisWorkbook.Worksheets 'This was a check on the worksheet name for excluding some worksheets that I didn't want to export 'If ws.name <> "Instructions" And ws.name <> "Parameters" And ws.name <> "BI Data & Worksheet" Then 'This makes the current sheet its own workbook so it can be saved. Sheets(ws.name).Copy 'Not sure what I was doing here 'For Each cell In [b:b] 'If cell.Value = "~" Then cell.ClearContents ''put any value you want here 'Next cell ActiveWorkbook.SaveAs filename:=SaveToDirectory & ws.name & ".csv", FileFormat:=xlCSV ActiveWorkbook.Close SaveChanges:=False ThisWorkbook.Activate 'End If Next Application.DisplayAlerts = False ThisWorkbook.SaveAs filename:=CurrentWorkbook, FileFormat:=CurrentFormat Application.DisplayAlerts = True ' Temporarily turn alerts off to prevent the user being prompted ' about overwriting the original file. End Sub