[英]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.