【发布时间】:2015-02-26 05:35:03
【问题描述】:
我需要创建一个宏,它将指定的工作表作为其自己的工作簿发送到电子邮件地址。此工作表不是活动工作表。基本上,我需要一页按钮,然后对每个按钮进行编程,以将工作簿中的特定工作表(选项卡等)作为电子邮件的附件发送。同样,正在发送的工作表与包含按钮的工作表不同。请指教。
【问题讨论】:
-
只要您对每张工作表都有明确的路径,就应该相当容易。将在一秒钟内提出解决方案
我需要创建一个宏,它将指定的工作表作为其自己的工作簿发送到电子邮件地址。此工作表不是活动工作表。基本上,我需要一页按钮,然后对每个按钮进行编程,以将工作簿中的特定工作表(选项卡等)作为电子邮件的附件发送。同样,正在发送的工作表与包含按钮的工作表不同。请指教。
【问题讨论】:
那么,它未经测试,但至少应该为您指明正确的方向。如果其他人知道 sendUsing 位指的是什么,请刷新我的记忆! (如果没有,我会尝试查看并记住,因为其中大部分代码是直接从我一年前做的工作中提取的)
Sub copyAndEmail()
Dim sendUsing, smtpServer, smtpPort, pathToWB As String
Dim wbOpen, wbSend As Workbook
sendUsing = "" 'cant remember what this one is actually, but I have it on "2" - will look through some old notes and check
smtpServer = "" 'this is your mail server IP
smtpPort = "" 'and your mail server port
pathToWB = "c:\Your\Sheet\Location.xls"
Set wbOpen = Workbooks.Open(pathToWB)
wbOpen.Sheets("Your Sheet").Copy
getTemp = Environ$("tmp")
If getTemp = vbNullString Then
getTemp = Environ$("temp")
End If
Set wbSend = ActiveSheet.SaveAs(getTemp & "\" & Format(Now(), "ddmmyy_hhmm") & ".xls")
Set objMessage = CreateObject("CDO.Message")
With objMessage
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = sendUsing
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpPort
.Configuration.Fields.Update
.Subject = "" 'Insert Subject Here
.From = "" 'insert "From" email address
.To = "" 'insert "To" email address
.TextBody = "" 'Insert Body Here
.AddAttachment wbSend ' attachment
.Send
End With
Kill wbSend
End Sub
【讨论】: