我想将范围(a1:k38)从工作表复制到新工作簿,然后必须通过gmail发送新工作簿。 邮件发送工作,但附件不能打开,说它腐败,如果我附加另一个.xls文件。此外,我无法让代码工作将图片范围复制到新工作簿。
到目前为止我有什么
TempFilePath = Environ$("temp") & "\"
TempFileName = "Copy of " & wb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
FileExtStr = "." & LCase(Right(wb.Name, Len(wb.Name) - InStrRev(wb.Name, ".", , 1)))
wb.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "someone@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*******"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Update
End With
With iMsg
Set .Configuration = iConf
.To = "me@hotmail.com"
.CC = ""
.BCC = ""
.From = """Dave"" <me@hotmail.com>"
.Subject = "New form"
.AddAttachment TempFilePath & TempFileName & FileExtStr
.Send
End With
Kill TempFilePath & TempFileName & FileExtStr