【发布时间】:2015-10-07 19:41:45
【问题描述】:
长期以来,我一直使用宏通过邮件发送 Excel 工作表,但是当我更新到 Windows 10 时,一切都失败了,我不明白为什么。这是代码:
TempFilePath = Environ$("temp") & "\"
TempFileName = Range("B2") & " " & Format(Now, "dd-mmm-yy")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
' Change the mail address and subject in the macro before
' running the procedure.
With ActiveSheet
Set rngTo = .Range("B1")
Set rngCc = .Range("B3")
Set rngSubject = .Range("B2")
Set rngBody = .Range("B2")
End With
With OutMail
.To = rngTo
.CC = rngCc
.BCC = ""
.Subject = rngSubject
.Body = "Adjunto para tu revisión y comentarios"
.Attachments.Add Destwb.FullName
' You can add other files by uncommenting the following statement.
'.Attachments.Add ("C:\test.txt")
' In place of the following statement, you can use ".Display" to
' display the mail.
.Send
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
' Delete the file after sending.
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
问题出在.to, .cc, .subject 部分。
如果我调试代码我可以看到变量被填充,例如:
但是当它发送或显示字段时,它们是空的。另外,如果手动填写.to="a@a.com" 也可以。
你知道它是什么吗?
【问题讨论】: