将Excel附件另存为.txt - 使用Outlook 2010中的vba宏打开

时间:2016-01-15 12:25:20

标签: excel vba outlook

我在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

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

很抱歉,如果不是我想要的那么清楚。

不起作用的部分是:

xlApp.SaveAs strFile,FileFormat:= xlText

我正在从Outlook 2010运行这个,我不明白为什么当我尝试将excel保存为纯文本(机智标签分隔)时,工作原理不正常,我做错了什么?

感谢大家的回复。

1 个答案:

答案 0 :(得分:1)

这会将其保存为csv。我不确定你真的想要一个纯文本文件,因为你会丢失所有的列结构..

> > PWD < 257 "/" is current directory.
> * Entry path is '/'
> > CWD Products < 250 Requested file action okay, completed.
> > CWD OwnershipDetailV2 < 250 Requested file action okay, completed.
> > PASV
> * Connect data stream passively < 227 Entering Passive Mode (204,8,135,60,43,24)
> *   Trying 204.8.135.60... connected
> * Connecting to 204.8.135.60 (204.8.135.60) port 11032
> > TYPE I < 200 Type set to I.
> > SIZE OwnershipDetailV2Full20160110.zip < 451 Requested action aborted: session in inconsistent state.
> * ftp server doesn't support SIZE
> * Instructs server to resume from offset -1294967295
> > REST -1294967295 < 554 Invalid REST argument.
> * Couldn't use REST
> ** Resuming transfer from byte position -1294967295   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
>                                  Dload  Upload   Total   Spent    Left  Speed   0     0    0     0    0     0      0      0 --:--:--  0:00:01
> --:--:--     0* Closing connection #0
> 
> %CURL-E-FTP_COULDNT_USE, FTP REST command failed

这是我在某个时候写的一个函数,用于导出整个工作簿。它将每个工作表放入其自己的文本文件中。

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