×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

so you can modify the code now

Here is the sample code, it use VBA
First you should create a reference to the Outlook Object Library in the VBEditor

Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
With objMail
.To = "name@domain.com"
.Subject = "whatever"
.Body = "this is a test" + vbCrLf
.Attachments.Add "C:\1.prn", _
olByValue, , "print file 1"
.Attachments.Add "C:\2.prn", _
olByValue, , "print file 2"
.Display
End With
Set objMail = Nothing
Set objOL = Nothing
if you want automatic send, change .Display to .Send
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 在excel的macro里面,有谁知道,如何写一段code,让缺省的邮件application打开并附加2个文件作为附件?1个文件我用record macro就做到了,2个就不知道如何做了,谢谢
    • 把record好的代码贴上来,有大虾帮你修改!
      • 一个文件的很简单,是从菜单走的,2个文件应该是完全不一样的机制了
        Application.Dialogs(xlDialogSendMail).Show
    • 举手,我应该会吧。刚写完一个OUTLOOK OLE应用,收和发。我有什么好处?用VB APPLICATION。 2 DAYS WORK。
      • 啊,要2days?没简单方法啊?2天就算了,太麻烦了,只是个小报表而已,要经常改动的,thanks anyway
      • 2 days? 2 hours should be more than enough.
        • 大家认准了,名牌,这位大姐/哥确实是IT高手,准确回答过我N多问题
    • 将macro转换成Excel VBA code,在这个基础上修改成更复杂的。要看看VBA的书。
      • 呵呵,我清楚这点,自己也写过2,3个烂VB程序,让我现在想我是想不出,要去看书先,直到这里高手多,就想试试有没有什么10行的代码可以解决问题的,如果没有也只有罢了,我连发2次就得了
        • Excel VBA 就是玩的,抠得再深也不常用。能发2次把活干了就行了。
          • 嗯,我是大烂人,IT啥都不懂,最擅长就是人家有代码,我来看,然后copy+paste修修补补就成新代码了,哈哈
            • so you can modify the code now
              Here is the sample code, it use VBA
              First you should create a reference to the Outlook Object Library in the VBEditor

              Dim objOL As New Outlook.Application
              Dim objMail As MailItem
              Set objOL = New Outlook.Application
              Set objMail = objOL.CreateItem(olMailItem)
              With objMail
              .To = "name@domain.com"
              .Subject = "whatever"
              .Body = "this is a test" + vbCrLf
              .Attachments.Add "C:\1.prn", _
              olByValue, , "print file 1"
              .Attachments.Add "C:\2.prn", _
              olByValue, , "print file 2"
              .Display
              End With
              Set objMail = Nothing
              Set objOL = Nothing
              if you want automatic send, change .Display to .Send
              • 厉害,凭空就能写出代码来,我正热完饭,吃完了就试试,万分感谢
                • not 凭空 la.
                  • anyway, marked, coz
                    我马上会有很多编代码的作业,据说超难,有人有过一个礼拜都会在学校的LAB里呆着,每天3点AM睡觉的经历。。。到时候,请您指点一下,如何?:-)
                    • 你找对人了。。。
                      • :O did i miss somebody? :-P
                        • nonono, i'm not kidding...
              • 牛人啊,不用调试就成功了,厉害,就是徒弟我太愚笨,找怎么加outlook library都找了半天,呵呵,anyway Thanks a lot.
              • 又试了一次,to里面写名字都可以,想想也是,应该是outlook会去解释名字的,哈哈
              • 牛啊!已经收录。另外,这好像是通用码?在其它office里也可以用的,比如word 和access。是吗?
              • 可怕——你怎么什么都会啊!
                • 你也发现了?他/她好像是全才,啥IT的东西都懂,而且都精,可怕