ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

斑竹:能否讲解以下代码的作用?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2004-7-28 17:15 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

斑竹:能否讲解以下代码的作用?

Option Explicit

' MatroExpungeIMAP ' code by Matro ' rome, italy, 2004 ' matro@email.it ' ' this code may be used in compiled form in any way you desire. this ' file may be redistributed unmodified by any means PROVIDING it is ' not sold for profit without the authors written consent, and ' providing that this notice and the authors name is included. If ' the source code in this file is used in any commercial application ' then acknowledgement must be made to the author of this file ' (in whatever form you wish). ' ' this file is provided "as is" with no expressed or implied warranty. ' the author accepts no liability for any damage caused through use. ' ' important: expect bugs. ' ' use and enjoy. :-)

Const MATROEXPUNGEIMAP_RELEASE = "004" Const MATROEXPUNGEIMAP_CLICKYESMLS = 2000 Const TemporaryFolder = 2

Public Sub MatroExpungeIMAP() Dim appOutlook, nsMapi, barEdit, btnPurge, rootFolder, btnConnect Dim ClickYesPath As String Set appOutlook = CreateObject("Outlook.Application") Set nsMapi = appOutlook.GetNamespace("MAPI") ' the macro is all here: it selects the Expunge button... Set barEdit = ActiveExplorer.CommandBars("Edit") Set btnPurge = barEdit.FindControl(msoControlButton, 5583, , , True) Set barEdit = ActiveExplorer.CommandBars("File") Set btnConnect = barEdit.FindControl(msoControlButton, 9441, , , True) If btnPurge Is Nothing Or btnConnect Is Nothing Then MsgBox "Select a valid IMAP folder once at least, then run this macro again.", vbInformation, "MatroExpungeIMAP" Exit Sub End If If nsMapi.Offline Then MsgBox "Go Online, then run this macro again.", vbInformation, "MatroExpungeIMAP" Exit Sub End If ' ...and it selects the 'Yes' button in the confirm dialog... ClickYesPath = ExpungeCreateClickYesScript() ' ...on each IMAP folder, recursively... For Each rootFolder In nsMapi.Folders() Call ExpungeCurrentFolder(nsMapi.Folders(rootFolder.Name), btnPurge, btnConnect, ClickYesPath) Next

' ...then it sits back on its window... Set ActiveExplorer.currentFolder = nsMapi.GetDefaultFolder(olFolderInbox)

' ...and that's all madams and sirs. :-)

End Sub

Private Sub ExpungeCurrentFolder(parentFolders, btnPurge, btnConnect, ClickYesPath As String)

Dim currentFolder

For Each currentFolder In parentFolders.Folders Call ExpungeCurrentFolder(currentFolder, btnPurge, btnConnect, ClickYesPath) DoEvents If currentFolder.DefaultItemType = olMailItem And Not btnConnect.Enabled Then Set ActiveExplorer.currentFolder = currentFolder If btnPurge.Visible Then If Len(ClickYesPath) > 0 Then Call Shell("wscript " & ClickYesPath, vbHide) End If btnPurge.Execute End If End If Next

End Sub

Private Function ExpungeCreateClickYesScript() As String

Dim fs, f ' basically, the auto click yes feature works by creating a VBScript routine ' which will be called asynchronously on a separate process. On Error Resume Next Set fs = CreateObject("Scripting.FileSystemObject") ExpungeCreateClickYesScript = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder), "MatroExpungeClickYes.vbs") Set f = fs.CreateTextFile(ExpungeCreateClickYesScript, True) f.WriteLine ("' this is part of MatroExpungeIMAP rel" & MATROEXPUNGEIMAP_RELEASE) f.WriteLine ("' MatroExpungeIMAP is an opensource macro for MS Outlook.") f.WriteLine ("'") f.WriteLine ("set sh=WScript.CreateObject(""WScript.Shell"")" & vbCrLf & "WScript.Sleep(" & (MATROEXPUNGEIMAP_CLICKYESMLS / 2) & ")") f.WriteLine ("activated = False: dt = 100: tw = " & MATROEXPUNGEIMAP_CLICKYESMLS) f.WriteLine ("Do While (Not activated And tw > 0)" & vbCrLf & "activated = sh.AppActivate(""Microsoft Office Outlook"")" & vbCrLf & "WScript.Sleep (dt): tw = tw - dt" & vbCrLf & "Loop") f.WriteLine ("If tw >= dt Then" & vbCrLf & "WScript.Sleep(dt): sh.SendKeys(""{TAB 2}{ENTER}"")" & vbCrLf & "End If") f.Close Set fs = Nothing If Err <> 0 Then ExpungeCreateClickYesScript = ""

End Function

TA的精华主题

TA的得分主题

发表于 2005-5-18 21:09 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2005-5-18 20:46 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-3-29 05:47 , Processed in 0.039425 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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