这是我的第一个问题。我想主修计算机科学,但与此同时,我恳请您在使用 VBA Excel 方面提供一些帮助。
我每天(工作日)都会收到具有相同文件名的 Outlook 电子邮件;我想对 VBA Excel 进行编程,以打开前一天晚上收到的 Outlook 附件。
所以,实际上有两件事:
- 编程 VBA Excel 以打开特定文件夹中的附件
- 删除同一封电子邮件,以便第二天我有相同的过程(所有文件都使用相同的文件名发送,因此我不想让自己感到困惑或复制并粘贴错误的当天数据)。
我编写了以下代码,但需要从 Outlook 打开 Excel 工作簿,而不是 C 驱动器:
Sub Test()
Dim WB As Workbook 'designate variables
Dim sSaveFileName As String
sSaveFileName = Format(Now() - 1, "MM-DD-YYYY") 'save as received date,
yesterday
' not needed >>>>> 'Set WB =
Workbooks.Open("C:\Users\nader\OneDrive\Documents\openthisexcel.xlsx")
Windows("openthisexcel.xlsx").Activate 'activate opened excel attachment
Sheets("Sheet1").Select
Range("A1:A50").Select
Selection.Copy 'select range and copy
Windows("macroExcel.xlsm").Activate 'activate xlsm template (another
workbook)
Sheets("Sheet1").Select
Range("A1:A50").Select
Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False 'select range
and paste from one excel to another
WB.SaveAs Filename:= _
"C:\Users\nader\OneDrive\Documents\openthisexcel.xlsx" &
sSaveFileName & ".xlsx" 'save received excel using filename and
the date it was received in Outlook
WB.Close 'close the excel attachment
End Sub
请提供一些帮助,以从文件夹中打开 Excel 附件,以及如何使用 VBA 在 Outlook 中删除电子邮件(包括 Excel 附件)。
我读了一些 Stack Overflow 帖子,但无法理解它们(这里只是初学者)。
Look at 从 Outlook 下载附件并在 Excel 中打开 https://stackoverflow.com/questions/11781320/download-attachment-from-outlook-and-open-in-excel。这将满足您对 Excel 的要求。
但是,您还有另一种选择,即编写 Outlook 宏。看按计划运行 Outlook 宏 https://www.slipstick.com/developer/code-samples/running-outlook-macros-schedule/。这样,您就可以每天在 Outlook 中自动运行宏(只要 Outlook 打开)以提取数据。宏的内容与第一个链接中的内容基本相同。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)