Is there a way where I can delete all the emails from a folder at a set time everyday when AutoArchive is disable on my system ? Typically I would use AutoArchive to resolve this but currently it is not an option.
Set up a daily recurring task, with a reminder and a unique subject.
In the ThisOutlookSession module
Option Explicit
Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass = "IPM.Task" Then
If Item.Subject = "Scheduled Deletion" Then
DeleteFromToBeDeleted
End If
End If
End Sub
Sub DeleteFromToBeDeleted()
Dim myFolder As Folder
Dim i As Long
Set myFolder = Application.GetNamespace("MAPI"). _
GetDefaultFolder(olFolderInbox).Folders("ToBeDeleted")
For i = myFolder.items.Count To 1 Step -1
myFolder.items(i).Delete
Next i
Set myFolder = Nothing
End Sub
Related
I found a lot of examples about uploading a resource to ALM via UFT.
However there were always a resource already created in ALM.
How can i create and upload a resource to ALM using UFT?
My problem is I don't know how many resources I am going to need, so I have to dinamically create resources and then upload them.
I do not want to upload files as attachments to the run.
Thank you
I think I found the answer here: http://www.codetweet.com/other/create-new-resource-almqc-using-ota/
Sub CreateNewResource(resourceFolderId As Integer, fileType As String, fileName As String, fileParentFolderPath As String)
On Error GoTo Errhandler:
'--- Represents a file or folder stored in the Quality Center repository
Dim resource As QCResource
'--- Represents a QC resource folder.
Dim resourceFolder As QCResourceFolder
'--- Services for managing QC resources.
Dim resourceFactory As QCResourceFactory
'--- Services for managing QC resource folders.
Dim resourceFolderFactory As QCResourceFolderFactory
'--- Services to manage resource storage.
Dim testResourceStorage As IResourceStorage
Dim resourceItem
Dim resourceFound As Boolean
' ***TDConn is TDConnection class object.Create this object before using this function.
Set resourceFolderFactory = TDConn.QCResourceFolderFactory
Set resourceFolder = resourceFolderFactory.Item(resourceFolderId)
Set resourceFactory = resourceFolder.QCResourceFactory
Set currResourceList = resourceFactory.NewList("")
For ItemCount = 1 To currResourceList.Count
currItem = currResourceList.Item(ItemCount).Name
If UCase(currItem) = UCase(fileName) Then
Set resourceItem = currResourceList.Item(ItemCount)
resourceFound = True
Exit For
End If
Next
If Not resourceFound Then
'--- Create a resource
Set resourceItem = resourceFactory.AddItem(fileName)
resourceItem.ResourceType = fileType
resourceItem.fileName = fileName
resourceItem.Post
'--- Check if the resources added successfully
Set currResourceList = resourceFactory.NewList("")
For ItemCount = 1 To currResourceList.Count
currItem = currResourceList.Item(ItemCount).Name
If UCase(currItem) = UCase(fileName) Then
resourceFound = True
Exit For
End If
Next
If resourceFound Then
'--- Attach the file to resource
resourceItem.vC.CheckOut ""
Set testResourceStorage = resourceItem
testResourceStorage.UploadResource fileParentFolderPath, False
resourceItem.vC.CheckIn "Automated check-in by utility" & Now
Else
oFile.WriteLine ("Recently added new resource not found on ALM.Try again later.")
Exit Sub
End If
Else
resourceItem.vC.CheckOut ""
Set testResourceStorage = resourceItem
testResourceStorage.UploadResource fileParentFolderPath, False
resourceItem.vC.CheckIn "Automated check-in by utility" & Now
End If
Set resourceFolderFactory = Nothing
Set resourceFolder = Nothing
Set resourceFactory = Nothing
Set currResourceList = Nothing
Exit Sub
Errhandler:
MsgBox("Error Executing - `CreateNewResource` ; Error Uploading file " & fileName)
Exit Sub
End Sub
I want to use a macro in outlook 2013. This macro is supposed to mark any emails arriving a specific folder ('work' folder) as read. I'm not familiar with vb. Any help/guidance is much appreciated!
No sure, I have heard this one before of wanting emails automatically read. You have two options:
a) Use Ctrl-A (select all mail in folder), Ctrl-Q (mark selection as read)
b) Use New Email Event something like:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
vID = Split(EntryIDCollection, ",")
Dim i as Long, objMail as Outlook.MailItem
For i = 0 To UBound(vID)
Set objMail = Application.Session.GetItemFromID(vID(i))
objMail.Unread = False
Next i
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
' version to select folder
Dim i As Long, objMail As Outlook.MailItem, mpfInbox As Outlook.Folder
Set mpfInbox = Application.GetNamespace("MAPI").Folders("YOURACCOUNT").Folders("[Gmail]").Folders("Sent Mail")
For i = 1 To mpfInbox.Items.Count
If mpfInbox.Items(i).Class = olMail Then
Set objMail = mpfInbox.Items.Item(i)
objMail.UnRead = False
End If
Next i
End Sub
You can set up a rule which can trigger your macro.
I'd not suggest working with the NewMailEx event because it is not fired in some case and may introduce issues. See Outlook NewMail event unleashed: the challenge (NewMail, NewMailEx, ItemAdd) for more information.
I have rules set up to copy emails containing certain keywords to specific folders and mark as read.
The problem i'm having is when it copies those emails to the folders it marks the original email in the inbox as read, and which can cause me to miss the message.
If i don't mark it as read then when i read it in the Inbox it stays unread in the specific folder.
I cant find any rule properties to accomplish this, anyone have any ideas?
Set the rules to copy to the target folders but not mark as read.
Put this untested code in the ThisOutlookSession module. Assumes the target folders are directly under the Inbox. If buried deeper, add .Folders as necessary.
Option Explicit
' one line for each target folder
Private WithEvents myOlItemsA As Outlook.Items
Private WithEvents myOlItemsB As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' one line for each target folder
Set myOlItemsA = objNS.GetDefaultFolder(olFolderInbox).Folders("targetfoldernameA").Items
Set myOlItemsB = objNS.GetDefaultFolder(olFolderInbox).Folders("targetfoldernameB").Items
End Sub
' one copy of ItemAdd code for each target folder
Private Sub myOlItemsA_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
Msg.Unread = False
End If
ProgramExit:
Set Msg = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Private Sub myOlItemsB_ItemAdd(ByVal item As Object)
' same code as for myOlItemsA
End Sub
Code based on this post Using VBA to read new Outlook Email?
The rules move mail to target folders. The ItemAdd code acts on the items added to the target folders.
My company uses a cloud Exchange system that deletes emails when they have been in the Deleted Items folder for 30 days (we use Outlook 2010 clients). I want a script that would move all email from the Deleted Items folder to a second folder called "Trash". I was able to find most of the following script online but it isn't working for me and I'm not sure what is missing/incorrect. Any help is appreciated...
Sub MoveDeletedItems()
Dim oSource As Outlook.MAPIFolder
Dim oTarget As OutlookMAPIFolder
Dim oDummy As Object
Dim oToMove As Object
Dim colItems As Outlook.Items
Dim i As Long
Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oTarget = oSource.Folders.Folder("Trash")
Set colItems = oSource.Items
For i = colItems.Count To 1 Step -1
Set oToMove = colItems(i)
Set oDummy = oToMove.Move(oTarget)
Next
End Sub
Fist you have a lot of stuff going on you dont need
Here is an example with comments that can be run as a macro within outlook.
Sub MoveDeletedItems()
'setup some error checking
On Error GoTo err_rpt
Dim oSource As Outlook.MAPIFolder
Dim oTarget As Outlook.MAPIFolder
Dim oItem
'get the deleted Items folder
Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
'get the folder under the Deleted Items folder called Trash
Set oTarget = oSource.Folders("Trash")
'loop through all the items in the source folder
For Each oMailItem In oSource.Items
'move the item to the target folder
oItem.Move oTarget
Next
err_rpt:
If Err.Number > 0 Then
MsgBox Err.Description
End If
'release the folders
Set oTarget = Nothing
Set oSource = Nothing
End Sub
I need some help please. I have managed to create a task in outlook using VB and SendItem. My problem is the code I'm using is creating two tasks and not just the one I want.
I have tried removing the .Save as I thought this was the cause but it still adds two tasks. I have added breakpoints to the code to ensure its not cycling round twice for some obscure reason and it just executes once.
Would appreciate someone telling me the obvious please
Code snippet:
`If bNotFount = False Then
Set Ns = Application.GetNamespace("MAPI")
Set ItemT = GetCurrentItem()
Set taskFolder = Ns.GetDefaultFolder(olFolderTasks)
Set olTask = Ns.GetDefaultFolder(olFolderTasks).Items.Add(olTaskItem)
With olTask
.Subject = ItemT.Subject
.Attachments.Add ItemT
.Body = ItemT.Body
.DueDate = Now + 1
.Move taskFolder
.Save
.Display 'show the task to add notes
End With
End If'
You don't need to move it to the default task folder because you saving it there anyway.
Just remove .Move taskFolder line.
I updated your code:
Private Sub Application_ItemSend(Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
Dim ns As Outlook.NameSpace
Dim taskFldr As Outlook.Folder
Dim olTask As Outlook.TaskItem
' If bNotFount = False Then
Ns = Application.GetNamespace("MAPI")
taskFldr = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks)
olTask = taskFldr.Items.Add
With olTask
.Subject = Item.Subject
.Attachments.Add(Item)
.Body = Item.Body
.DueDate = Now + 1
.Save()
.Display() 'show the task to add notes
End With
' End If
End Sub