---
title: "Flytta mail mha vb-script och Outlook.Application"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/176771-flytta-mail-mha-vb-script-och-outlook-application"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "devotion"
published: "2009-02-08T22:35:38.000Z"
updated: "2009-02-09T12:18:37.000Z"
replies: 1
views: 384
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/176771-flytta-mail-mha-vb-script-och-outlook-application"
---

# Flytta mail mha vb-script och Outlook.Application

## #1 — devotion, 2009-02-08T22:35Z

Hej,

Jag har knåpat ihop en liten kod som läser av information i ett mail i Outlook. Jag har fått till det så att informationen läses och mailet flyttas till borttaget. Nu vill jag dock flytta mailet till en speciell mapp. Men jag får felmeddelande enligt bifogad bild.

```
Sub main
	dim oOutlook, oSafeMailItem, oMailItem, oAttach, oDestFolder
	dim oNS, oInbox, oItem, oItems

	set oOutlook = CreateObject("Outlook.Application") 
	Set oSafeMailItem= CreateObject("Redemption.SafeMailItem")

	Set oNS=oOutlook.GetNamespace("MAPI")
	Set oInbox=oNS.GetDefaultFolder(6)
	Set oItems = oInbox.Items

	For Each oItem In oItems
		If oItem.Subject="Felanmälan" Then
			oSafeMailItem.Item=oItem
			If CreateTaskFromMailItem(oSafeMailItem)>=0 Then
				[B]oItem.Move (oInbox.Folders("Test"))[/B]
			End If
		End If
	Next
	
	Set oSafeMailItem=Nothing
	Set oInbox=Nothing
	Set oNS=Nothing
	Set oOutlook=Nothing
End Sub
```

```
oItem.Delete
```

...funkar...

Någon som har några bra idéer?

Mvh
Henrik

Bilagor:

- [outlook.png](https://www.webforum.nu/a/19889.png)

Permalänk: https://www.webforum.nu/p/176771

## #2 — devotion, 2009-02-09T12:18Z

Efter en hel del sökande och lite klurande så...

```
Sub main()
	dim oOutlook, oSafeMailItem, oMailItem, oAttach, oDestFolder
	dim oNS, oInbox, oItem, oItems

	set oOutlook = CreateObject("Outlook.Application") 
	Set oSafeMailItem= CreateObject("Redemption.SafeMailItem")

	Set oNS=oOutlook.GetNamespace("MAPI")
	Set oInbox=oNS.GetDefaultFolder(6)
	
	[B]Set oDestFolder=oNS.Folders("Postlåda - Henrik Lindell").Folders("Mottagna uppdrag")[/B]
	Set oItems = oInbox.Items

	For Each oItem In oItems
		If oItem.Subject="Felanmälan" Then
			oSafeMailItem.Item=oItem
			If CreateTaskFromMailItem(oSafeMailItem)>=0 Then
				oItem.Move oDestFolder
			End If
		End If
	Next
	
	Set oSafeMailItem=Nothing
	Set oInbox=Nothing
	Set oNS=Nothing
	Set oOutlook=Nothing
End Sub
```

Permalänk: https://www.webforum.nu/p/2168151

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/176771-flytta-mail-mha-vb-script-och-outlook-application
