为什么我的代码没有保存任何具有特定邮件ID的邮件? [英] Why my code is not saving any mails having particular mail id?

查看:64
本文介绍了为什么我的代码没有保存任何具有特定邮件ID的邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用VBA自动化将包含一个特定邮件ID的所有电子邮件移动到硬盘文件夹



下面是我到目前为止的代码,但似乎没有给我回复任何文件夹中的邮件。如果有人可以建议我哪里出错了?



Hi all,

I am working on VBA automation to move all emails containing one specific mail Id to the hard drive folder

Below is the code I have got so far but seems it is not returning me any mails in folders. if anyone can suggest where I am going wrong?

Dim OlApp As Outlook.Application
Set OlApp = CreateObject("Outlook.Application")
Dim fldrpath As String
Dim oMails As Outlook.Items
Dim oMail As Object

fldrpath = "\\data\EMAILS\abc@gmail.com"

Dim NS As Outlook.Namespace
Dim Folder As MAPIFolder
Dim Olfolder As Outlook.MAPIFolder

Set NS = OlApp.GetNamespace("MAPI")
Set Olfolder = NS.GetDefaultFolder(olFolderInbox)

' Check subfolder for messages and exit of none found

Set oMails = Olfolder.Items
Set oMail = oMails.Find("[Sendername]= 'abc@gmail.com'")
While TypeName(oMail) <> "Nothing"
oMail.Move fldrpath
Set oMail = oMails.FindNext
Wend





< b>我尝试了什么:



上面的代码是用excel VBA编写的,并尝试连接outlook app和inbox文件夹。



What I have tried:

The above code is written in excel VBA and tried to connect with outlook app and inbox folder.

推荐答案

我们无法告诉您为什么它不起作用,因为我们没有您的代码正在使用的数据。机会真的很好你的。电话找不到任何匹配你给它的字符串,因为我真的怀疑一个电子邮件地址中有'字符。



但是,在论坛中要求其他人告诉你你的代码正在做什么以及它正在使用什么并不是正确的事情。正确的做法是在VBA中的调试器下运行代码并检查变量的内容,这样你就可以理解代码在做什么了。



调试器是没有调试代码。它在那里调试你,你了解它所在的代码和环境。
We can't tell you why it's not working because we don't have the data your code is working with. Chances are really good your .Find call can't find anything that matches the string you're giving it, because I really doubt an email address has ' characters in it.

But, asking in a forum for other people to tell you what you're code is doing and what it's working with is not the correct thing to do. The correct thing to do is to run the code under the debugger in VBA and examine the contents of variables so you can understand what the code is doing.

The debugger is not there to debug the code. Its there to debug YOU and you're understanding of the code and the environment its working in.


这篇关于为什么我的代码没有保存任何具有特定邮件ID的邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆