changing locating inbox Via VB HELP

R

Rivers

hi all i have this macro i gained from
http://www.fontstuff.com/outlook/oltut01.htm to remove all attatchments from
my emails and putting them directly into a folder selected by myself but this
works only for my default mailbox however i would like to change this to
another account as tis is required onl for this inbox. the code is as follows

Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)

i believe i need to change something on the last line
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
but dont understand or no what the code is. im not at all affuent in VBA
coding for Outlook but have some understanding for excel and access so any
help would be appreciated.

thanks

Rivers
 
K

Ken Slovak - [MVP - Outlook]

That line needs to be changed to use the NameSpace.GetSharedDefaultFolder()
method. Look in the VBA Object Browser for more on that method, but you
basically suppy a Recipient object and folder type somewhat like this:

Dim oRecip As Outlook.Recipient

Set oRecip = ns.CreateRecipient("Joe Foobar")
If oRecip.Resolve() Then
Dim otherInbox As Outlook.MAPIFolder
Set otherInbox = ns.GetSharedDefaultFolder(oRecip, olFolderInbox)
Else
'could not create recipient
End If
 
R

Rivers

unfortunatly i dont understand why we need a recipriant?

heres my code:
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Copied in on") ' Enter correct subfolder
name.

I need to set my inbox line to my new mail inbox called "Main Dep" so where
the line " Set Inbox = ns.GetDefaultFolder(olFolderInbox)" states default i
would like to set to inbox = "Main Dep" im sorry if this has already been
xplained but i didnt understand please help

Rivers
 
K

Ken Slovak - [MVP - Outlook]

To open a folder (Inbox) in a different mailbox than your own you need to
use GetSharedDefaultFolder(), as I said. You need a recipient object because
that's what that method requires. I showed you the code needed, all you have
to do is substitute the name of the owner of that mailbox to make it work.
 
R

Rivers

Hi Ken im sorry for sounding like a total noob but outlook classess and
methods are alien to myself ive tried to incorperate your code within the new
code and it gives me an error "Object could not be found" can you please
point out where im going wrong. the code is as follows

Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult
Dim oRecip As Outlook.Recipient

Dim otherInbox As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set oRecip = ns.CreateRecipient("Main")

If oRecip.Resolve() Then

Set otherInbox = ns.GetSharedDefaultFolder(oRecip, olFolderInbox)
Else
MsgBox "No Mailbox"
End If

Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = otherInbox.Folders("Flash Recieved")

thank you again your time is greatly appreciated
 
K

Ken Slovak - [MVP - Outlook]

Is "Main" the name of that mailbox you want to log into? You need to use the
actual name of the user who owns that mailbox, for example for me on my
Exchange server it would be "Ken Slovak".

What line fires the error? Put your cursor in the code and set a breakpoint
on the Set ns = GetNameSpace("MAPI") line. When you hit the breakpoint step
the code (F8) until you get to the line that fires the error.

You also need to make sure that the permissions of the logon that's running
this code are set so that logon has permissions to log into the mailbox, the
Inbox there and the "Flash Received" folder under that Inbox.
 
R

Rivers

ken you star you were right all along it was me and my stupidity!!!! i am
looking for folders that are inside my inbox however i had the folders on the
outside! lol sorry Ken thanks very much for you help. greatly apreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top