ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 如何给外发邮件自动编号实现邮件控制

[复制链接]

TA的精华主题

TA的得分主题

发表于 2010-12-18 17:45 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
办公室和工厂相隔两地,经常会有办公室发出的邮件工厂漏收的情况,现在解决的办法是办公室每发出一封电邮就在标题栏手动编一个流水号,但因为有很多人,又要按顺序取号,很麻烦。可否通过宏实现邮件自动编号呢?(很多人按统一流水号编号,不能重复)
(ps:关于收条功能,如果收件人设置为不回复收条,也是无法达到邮件控制的目的。)

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-12-19 18:21 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
自动编号加到什么地方?

subject还是哪里?

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-12-20 09:35 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2010-12-20 12:45 | 显示全部楼层
拷到ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

If TypeName(Item) <> "MailItem" Then Exit Sub

Dim myFile As String
Dim No As Integer

myFile = Dir("*.d99")
If myFile = "" Then
No = 1
Else
pos = InStr(1, myFile, ".")
No = Left(myFile, pos - 1)
No = No + 1
End If

Kill "*.d99"

CreateFile No

Dim newSubject As String

newSubject = "(" & No & ")" & Item.Subject

Item.Subject = newSubject


End Sub


Function CreateFile(No As Integer)
Dim sFilename As String
sFilename = No & ".d99"
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(sFilename, True)
a.Close
End Function

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-12-21 14:54 | 显示全部楼层
十分感谢斑竹。
1.初次运行需手动添加一个.d99文件或将kill语句放到if语句内,否则报错。
2.在建立和检索文件语句里添加路径(共享目录),这样可以实现多人按统一流水号编号(测试ok)。

另外并不是所有的邮件都是发给工厂即不是所有邮件都需要编号,所以设想将以上代码放到一个模块里,然后在新邮件item里添加一个类似“发送”的按钮,需要编号的邮件则点此按钮调用以上模块发送邮件,不需要编号的邮件则按OL发送按钮。
看了斑竹的VBA开发教程里的添加按钮的方法,但怎么将按钮添加到新邮件窗口呢?还请指教,多谢嗮。

TA的精华主题

TA的得分主题

发表于 2010-12-21 15:06 | 显示全部楼层
原帖由 sunhill 于 2010-12-21 14:54 发表
十分感谢斑竹。
1.初次运行需手动添加一个.d99文件或将kill语句放到if语句内,否则报错。
2.在建立和检索文件语句里添加路径(共享目录),这样可以实现多人按统一流水号编号(测试ok)。

另外并不是所有的邮件都 ...


看看第四讲,里面有代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-12-21 17:05 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
有点晕,按钮添加了,可是click事件调用模块出错-"子过程或函数未定义",需要申明吗,怎么申明或调用这个ItemSend, 谢

TA的精华主题

TA的得分主题

发表于 2010-12-21 21:20 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-12-22 11:46 | 显示全部楼层
Private WithEvents vsoCommbandButton As CommandBarButton
Private WithEvents vsoCommbandReplyAllWithAttach As CommandBarButton
Private WithEvents colInspectors As Outlook.Inspectors
Private WithEvents vsoCommbandReplyAllWithAttachInspector As CommandBarButton

Private Sub Application_Startup()

Call addTotalButton
Set colInspectors = Application.Inspectors

End Sub

'增加工具栏
Sub addTotalButton()

'On Error Resume Next
Dim vsoCommandBar As CommandBar

'得到要添加的工具栏
Set vsoCommandBar = Outlook.ActiveExplorer.CommandBars("Point")
'如果工具栏为空,则增加
If (vsoCommandBar Is Nothing) Then

Set vsoCommandBar = Outlook.ActiveExplorer.CommandBars.Add("Point", msoBarTop)

'在工具栏上增加一个按钮
Set vsoCommbandReplyAllWithAttach = vsoCommandBar.Controls.Add(1)
vsoCommbandReplyAllWithAttach.Caption = "Send w/3&AS Coding"
vsoCommbandReplyAllWithAttach.FaceId = 68
vsoCommbandReplyAllWithAttach.Style = msoButtonIconAndCaption

'显示增加的工具栏
vsoCommandBar.Visible = True

Else

Set vsoCommbandReplyAllWithAttach = vsoCommandBar.Controls(1)

End If

End Sub

'得到当前选择的邮件
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
        
    Set objApp = Application
    'On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
   
    Set objApp = Nothing
End Function

Private Sub vsoCommbandReplyAllWithAttach_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
'On Error Resume Next

Dim rpl As Outlook.MailItem
    Dim itm As Object
   
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.ReplyAll
        CopyAttachments itm, rpl
        rpl.Display
    End If
   
    Set rpl = Nothing
    Set itm = Nothing

End Sub

Sub colInspectors_NewInspector(ByVal Inspector As Inspector)
     On Error Resume Next
     Dim objCommandBar As CommandBar
     Set objCommandBar = Inspector.CommandBars("Point")
     If (objCommandBar Is Nothing) Then
     Set objCommandBar = Inspector.CommandBars.Add("Point", msoBarTop, , True)
     Set vsoCommbandReplyAllWithAttachInspector = objCommandBar.Controls.Add(msoControlButton, , , , True)
     vsoCommbandReplyAllWithAttachInspector.Caption = "Send w/3&AS Coding"
     vsoCommbandReplyAllWithAttachInspector.FaceId = 68
     vsoCommbandReplyAllWithAttachInspector.Style = msoButtonIconAndCaption
     objCommandBar.Visible = True
     Else
     Set vsoCommbandReplyAllWithAttachInspector = objCommandBar.Controls(1)
     End If
End Sub

Private Sub vsoCommbandReplyAllWithAttachInspector_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)

call 模块1.Application_ItemSend(ByVal Item As Object, Cancel As Boolean)  '<<这里报错-“子过程或函数未定义”
CreateFile

End Sub

TA的精华主题

TA的得分主题

发表于 2010-12-22 12:37 | 显示全部楼层
把Application_ItemSend里的代码拷到 vsoCommbandReplyAllWithAttachInspector_Click里

前面加上
Dim Item as MailItem
set Item = GetCurrentItem()
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-4-27 21:23 , Processed in 0.032997 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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