vba 如何通过电子邮件发送带有宏的 Excel 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20609119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:57:31  来源:igfitidea点击:

How to send an excel file with a macro by email

excelexcel-vbaemail-attachmentsvba

提问by Dov Miller

I recieved an excel workbook with data and I added a macro to it with a button that activates the macro. I have to return the excel workbook with the macro by email. I added the workbook to the email as an attachment. I wanted to check the attached file to see if everything is ok and I saw that the macro isn't there.

我收到了一个带有数据的 excel 工作簿,我向其中添加了一个宏,并带有一个激活宏的按钮。我必须通过电子邮件返回带有宏的 excel 工作簿。我将工作簿作为附件添加到电子邮件中。我想检查附件以查看是否一切正常,并且我看到宏不存在。

The excel file is macro enabled.

excel 文件已启用宏。

How should this be done? Thank you.

这应该怎么做?谢谢你。

回答by Punith GP

Save it as .XLSM before sending, it is working with small test. you can specify the workbook name also if more than one workbook is open.

发送前将其保存为.XLSM,它正在与小测试一起工作。如果打开了多个工作簿,您也可以指定工作簿名称。

Sub marco()
With ActiveWorkbook.Sheets(1)
Range("a21").Select
ActiveCell.Formula = "=sum(a2:a20)"
End With
    ActiveWorkbook.SaveAs _
    "C:\Documents and Settings\Desktop\file.xlsm", FileFormat:=52
    ActiveWorkbook.SendMail Recipients:="[email protected]"

End Sub