简体   繁体   English

使用宏和所有电子邮件发送工作簿

[英]Emailing Workbook With Macros and All

I have a workbook that I am trying to email with macros.我有一个工作簿,我试图用宏通过电子邮件发送它。 This way the recipient will also be able to use the macros that are included with the workbook.这样,收件人还可以使用工作簿中包含的宏。 This will make office life easier for my company.这将使我的公司的办公生活更轻松。 I have tried setting the saved file name to .xlsm, but that causes an error.我曾尝试将保存的文件名设置为 .xlsm,但这会导致错误。

This is my code (which is adapted from sources online)这是我的代码(改编自在线资源)

Sub MailGo()
 'Variable declaration
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String, MailSub As String, MailTxt As String

 'Turns off screen updating
Application.ScreenUpdating = False

 'Makes a copy of the active sheet and save it to
 'a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = "Text.xls"
On Error Resume Next
Kill "C:\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\Users\Public\Documents" & FileName

 'Creates and shows the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
    .To = "wesley.x.sherow@us.tel.com"
    .Cc = ""
    .Bcc = ""
    .Subject = "LotInput"
    .Body = "LotInput"
    .Attachments.Add WB.FullName
    .Display
    .send
End With

 'Deletes the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False

 'Restores screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub

您还需要在.SaveAs行中包含此参数。

FileFormat:=xlOpenXMLWorkbookMacroEnabled

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用vba打开另一个包含所有宏的工作簿 - Open another workbook with vba that contains all the macros 通过Excel API for Excel获取工作簿的所有VBA宏 - Get all the VBA macros of a workbook by JavaScript API for Excel 错误“此工作簿中无法使用宏,或者所有宏都可能被禁用 - error "Macros is not available in this workbook or all macro may be disabled 将宏和模块从一个工作簿复制到另一个工作簿,并使所有VBA工作在一个主工作簿中 - Copying the macros and modules from one workbook to another and have all the VBA work in one master workbook Excel VBA将工作表复制到新工作簿并在Outlook中通过电子邮件发送新工作簿 - Excel VBA Copying Sheets to a New Workbook and emailing the New Workbook in Outlook Excel 使用自定义 UI 编辑器制作的按钮时出错 - 无法运行宏“***”。 此工作簿或所有宏中的宏可能不可用 - Excel Error when using button made from Custom UI Editor- Cannot run the macro "***". The macros may not be available in this workbook or all macros Excel VBA-将工作簿复制到带有宏的新工作簿中 - Excel VBA - Copy Workbook into a new Workbook with the macros Excel 工作簿模块未出现在工作簿宏中 - Excel Workbook Modules Not Appearing in Workbook Macros 在工作簿打开事件中启用宏 - Enable macros in Workbook Open Event 从锁定的工作簿中提取宏 - Extract macros from locked workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM