VBA打开工作簿附加到Outlook模板

有没有办法在发送邮件之前打开附加到电子邮件模板的工作簿,进行编辑和保存? 我已经使用Set Mesg = OutlookAp.CreateItemFromTemplate("C:\Template.oft")创build了mailitem对象,我可以看到附件,但是我看不到到目前为止打开它的方法。 如果有人有什么build议,或者知道这是根本无法完成的,我全都听。

看起来像我可能不得不在发送之前保存和编辑文件…仍然打开想法,但它看起来像是根本无法通过VBA打开附件

我假设你 Excel自动化Outlook。 这个解决scheme可能适用于你,但是正如你注意到的那样,它依靠保存附件并重新附加文件的操作版本。 假设您可以编写将“编辑”工作簿附件的代码,这应该适合您。

 Sub TestOutlookTemplate() Dim MyOutlook As Outlook.Application Dim MyMail As Outlook.MailItem Dim att As Outlook.Attachment Dim templatePath As String Dim tempFileName As String Dim attWorkbook As Workbook templatePath = "C:\users\david_zemens\desktop\Untitled.oft" tempFileName = "C:\users\david_zemens\desktop\tempexcelfile.xlsx" Set MyOutlook = CreateObject("Outlook.Application") Set MyMail = MyOutlook.CreateItemFromTemplate(templatePath) MyMail.Display For Each att In MyMail.Attachments If att.DisplayName Like "*.xls*" Then att.SaveAsFile tempFileName 'Now that you have saved the file, delete the attachment att.Delete 'Open the file Set attWorkbook = Workbooks.Open(tempFileName) 'Perform manipulation on the file attWorkbook.Sheets(1).Name = "Sheet ONE" 'Save fhe file attWorkbook.Save 'Close the file attWorkbook.Close MyMail.Attachments.Add tempFileName End If Next 'Send your mail (make sure you have added a recipient MyMail.Send Set attWorkbook = Nothing Set MyMail = Nothing Set MyOutlook = Nothing End Sub