ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 10742|回复: 15

(求助)有关VBA调用本地签名问题!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2015-1-22 15:59 | 显示全部楼层 |阅读模式
大家好。经过前两天大家的帮忙。我终于完成了一个简单的VBA程序。
不过,发现在它缺少邮件签名功能。在网上找了半天。
以下代码可以成功调用本地OUTLOOK签名。但我不会把它合到我的VBA中。试了好多次都失败了


sendemailatt(fina).rar (20.16 KB, 下载次数: 63)


Sub Mail_Outlook_With_Signature_Plain()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there"
'Use the second SigString if you use Vista or Win 7 as operating system
SigString = "C:\Users\Leroy\AppData\Roaming\Microsoft\Signatures\test.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.To = "cccc5900@hotmail.com"
.CC = "chen.lei@onsite.brocent.com"
.BCC = ""
.Subject = "This is the Subject line"
.htmlBody = strbody & Signature
'You can add files also like this
'.Attachments.Add ("C:\test.txt")
.Send   'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function


有人能教我下怎么弄吗?

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-1-22 16:04 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-1-22 16:52 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-1-22 18:48 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
自己顶自己顶自己顶自己顶自己顶自己顶自己顶自己顶

TA的精华主题

TA的得分主题

发表于 2015-1-22 22:59 | 显示全部楼层
cccc5900 发表于 2015-1-22 18:48
自己顶自己顶自己顶自己顶自己顶自己顶自己顶自己顶
  1. Function sendemail(ByVal smail As String, ByVal scc As String, ByVal sbcc As String, ByVal ssubject As String, ByVal sbody As String, ByVal sAtt1 As String, ByVal sAtt2 As String, ByVal sAtt3 As String)
  2.     On Error Resume Next

  3.     Dim olapp As Object
  4.     Dim olnamespace As Object
  5.     Dim olfolder As Object
  6.     Dim olmail As Object
  7.     Dim Signature As String
  8.     Set olapp = CreateObject("outlook.application")
  9.     Set olnamespace = olapp.getnamespace("mapi")
  10.     Set olfolder = olnamespace.getdefaultfolder(6)
  11.     Set olmail = olapp.CreateItem(0)
  12.     Dim myqianming As String

  13.     myqianming = "C:\Users\Administrator\AppData\Roaming\Microsoft\Signatures\wdw.txt"
  14.     With olmail
  15.         .Subject = ssubject
  16.         .To = smail
  17.         .CC = scc
  18.         .BCC = sbcc
  19.         myqianming = Module4.GetBoiler(myqianming)
  20.         .HTMLBody = sbody & "<br />" & myqianming
  21.         .BodyFormat = olFormatHTML  '//设置邮件格式 是否html 格式的
  22.         .attachments.Add sAtt1
  23.         .attachments.Add sAtt2
  24.         .attachments.Add sAtt3
  25.         .send
  26.     End With

  27. End Function


  28. Function GetBoiler(ByVal sFile As String) As String

  29. '//sFile  邮件签名的 所在文件
  30.     Dim fso As Object
  31.     Dim ts As Object

  32.     Set fso = CreateObject("Scripting.FileSystemObject")

  33.     If fso.FileExists(sFile) Then    '//文件存在的就打开文件 获得签名的文字
  34.         Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
  35.         GetBoiler = ts.readall
  36.         ts.Close

  37.     Else
  38.         '// 不存在的 返回空值

  39.         GetBoiler = ""
  40.     End If

  41. End Function
复制代码
改一下  更新代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-1-23 11:18 | 显示全部楼层
闻启学 发表于 2015-1-22 22:59
改一下  更新代码

谢了!!!我下班回家就更新试试!
我就是不明白, 为什么有的发邮件脚本用到FUNCTION。有的就不用。正在读新手入门!

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-1-23 22:57 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
闻启学 发表于 2015-1-22 22:59
改一下  更新代码

感谢大神!
现在有签名了!
但图片显示不出来,我再好好检查代码吧。
谢谢了!!!

TA的精华主题

TA的得分主题

发表于 2015-1-23 23:07 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
cccc5900 发表于 2015-1-23 11:18
谢了!!!我下班回家就更新试试!
我就是不明白, 为什么有的发邮件脚本用到FUNCTION。有的就不用。正在 ...

有什么好纠结的 各施各法 各庙各菩萨    每人的习惯不同

TA的精华主题

TA的得分主题

发表于 2015-1-23 23:09 | 显示全部楼层
cccc5900 发表于 2015-1-23 22:57
感谢大神!
现在有签名了!
但图片显示不出来,我再好好检查代码吧。

txt 文件是不能存放图片的 不用检查

你试一试提取html 文件吧  估计都不行

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-1-24 15:19 | 显示全部楼层
闻启学 发表于 2015-1-23 23:09
txt 文件是不能存放图片的 不用检查

你试一试提取html 文件吧  估计都不行

试了,果然!就是图片显示不出来。
Sub send()
    Dim strbody As String, strsubject As String
    Dim strmail As String, strcc As String, strbcc As String
    Dim stratt1 As String, stratt2 As String, stratt3 As String
   
   
    With ActiveSheet
        strmail = .Range("F4")
        strcc = .Range("f5")
        strbcc = .Range("f6")
        strsubject = .Range("F7")
        strbody = .Range("F8")
        stratt1 = .Range("f9")
        stratt2 = .Range("f10")
        stratt3 = .Range("f11")
        
    End With
    sendemail strmail, strcc, strbcc, strsubject, strbody, stratt1, stratt2, stratt3
    MsgBox "complete", vbInformation + vbOKOnly, "note"
End Sub
    Function sendemail(ByVal smail As String, ByVal scc As String, ByVal sbcc As String, ByVal ssubject As String, ByVal sbody As String, ByVal sAtt1 As String, ByVal sAtt2 As String, ByVal sAtt3 As String)
    On Error Resume Next
   
    Dim olapp As Object
    Dim olnamespace As Object
    Dim olfolder As Object
    Dim olmail As Object
    Dim signature As String
    Set olapp = CreateObject("outlook.application")
    Set olnamespace = olapp.getnamespace("mapi")
    Set olfolder = olnamespace.getdefaultfolder(6)
    Set olmail = olapp.createitem(0)
    Dim mysign As String
    mysign = "C:\Users\Ray\AppData\Roaming\Microsoft\Signatures\test.htm"
   
    With olmail
        .Subject = ssubject
        .to = smail
        .cc = scc
        .bcc = sbcc
        mysign = getboiler(mysign)
        .BodyFormat = olFormatHTML
        .HTMLBody = sbody & "<br />" & mysign
        .attachments.Add sAtt1
        .attachments.Add sAtt2
        .attachments.Add sAtt3
        .send
    End With
   
    End Function

Function getboiler(ByVal sfile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("scripting.filesystemobject")
If fso.fileexists(sfile) Then
Set ts = fso.getfile(sfile).openastextstream(1, -2)
getboiler = ts.readall
ts.Close
Else
getboiler = ""
End If

End Function
如果把 ON ERROR RESUME NEXT去掉。.BodyFormat = olFormatHTML就被标黄了,
现在不知道是什么问题。应该可以发有图片的签名吧?VBA这么强大,不应该不能啊?
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-8 19:41 , Processed in 0.042275 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表