{"id":4657,"date":"2021-11-11T08:39:40","date_gmt":"2021-11-11T08:39:40","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=4657"},"modified":"2021-11-11T08:41:31","modified_gmt":"2021-11-11T08:41:31","slug":"vbscript-to-save-unread-mail-outlook","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/vbscript-to-save-unread-mail-outlook\/28380.html","title":{"rendered":"VBScript To Save Unread Mail Outlook"},"content":{"rendered":"<p>Hey all,<\/p>\n<p>I have this script but when have added the unread<br \/>\nSection it doesn&#8217;t like it ?<\/p>\n<p>When it&#8217;s out it works like magic!<\/p>\n<p>Can someone take a look for me ?<\/p>\n<p>And if it&#8217;s not too much to ask after the attachment saves<br \/>\nTo make it &#8216;read&#8217; I have a little bit right at the end&#8230;<\/p>\n<p>Dim oFSO<br \/>\nSet oFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\noFSO.CreateFolder &#8220;C:\\Temp&#8221;<\/p>\n<p>&#8216;<br \/>\n&#8216;START TO EXTRACT FILES<br \/>\n&#8216;<\/p>\n<p>&#8216;below doesn&#8217;t seem to work<br \/>\n&#8216;<br \/>\nDim objMessage As Outlook.MailItem<\/p>\n<p>Const olFolderInbox = 6<br \/>\nSet objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)<br \/>\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)<\/p>\n<p>Set objFolder = objNameSpace.Folders(&#8220;Mailbox &#8211; Gmail&#8221;).Folders(&#8220;folder&#8221;).Folders(&#8220;Sub1&#8221;) \u00a0 \u00a0 \u00a0 \u00a0&#8216; FIRST FILE HERE<br \/>\nSet colItems = objFolder.Items<\/p>\n<p>For Each objMessage in colItems<br \/>\nIf objMessage.UnRead = True Then<br \/>\nintCount = objMessage.Attachments.Count<br \/>\nIf intCount &gt; 0 Then<br \/>\nFor i = 1 To intCount<br \/>\nobjMessage.Attachments.Item(i).SaveAsFile &#8220;C:\\Temp\\&#8221; &amp; \u00a0_<br \/>\nobjMessage.Attachments.Item(i).FileName<br \/>\nNext i<br \/>\nEnd If<br \/>\nEnd If<br \/>\nNext objMessage<\/p>\n<p>Set objFolder = objNameSpace.Folders(&#8220;Mailbox &#8211; Gmail&#8221;).Folders(&#8220;folder&#8221;).Folders(&#8220;Sub2&#8221;) \u00a0 \u00a0 \u00a0 \u00a0&#8216; SECOND FILE HERE<br \/>\nSet colItems = objFolder.Items<\/p>\n<p>For Each objMessage in colItems<br \/>\nIf objMessage.UnRead = True Then<br \/>\nintCount = objMessage.Attachments.Count<br \/>\nIf intCount &gt; 0 Then<br \/>\nFor i = 1 To intCount<br \/>\nobjMessage.Attachments.Item(i).SaveAsFile &#8220;C:\\Temp\\&#8221; &amp; \u00a0_<br \/>\nobjMessage.Attachments.Item(i).FileName<br \/>\nNext i<br \/>\nEnd If<br \/>\nEnd If<br \/>\nNext objMessage<\/p>\n<p>msgBox &#8220;UnRead Attachments Saved!&#8221;<\/p>\n<p>&#8216; maybe use this??<br \/>\n&#8216;<br \/>\n&#8216; If objUnreadMessage.UnRead = True Then<br \/>\n&#8216; \u00a0 \u00a0 objUnreadMessage.UnRead = False<br \/>\n&#8216; End If<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":5},"question-category":[55],"question_tags":[],"class_list":["post-4657","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/4657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=4657"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=4657"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=4657"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=4657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}