Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Saving outlook attachments with VBA code

Hi all,

I have my own outlook inbox and also a generic inbox I share with other
shift members. I have been able to save attachments from emails to my own
inbox using the code found at
http://www.dicks-clicks.com/excel/ol...ve_Attachments , but am
unable to do the same with my generic inbox - I get a message saying the
folder does not exist.

Does anyone know if/how this code can be adjusted to work on a generic
mailbox?

Thanks in advance...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Saving outlook attachments with VBA code

In the code the path mentioned is. Have you changed this and if so check
whether the path is a valid path and ends with "\"

MyPath = "C:\My Documents\Completed Survey\"

If this post helps click Yes
---------------
Jacob Skaria


"ewan7279" wrote:

Hi all,

I have my own outlook inbox and also a generic inbox I share with other
shift members. I have been able to save attachments from emails to my own
inbox using the code found at
http://www.dicks-clicks.com/excel/ol...ve_Attachments , but am
unable to do the same with my generic inbox - I get a message saying the
folder does not exist.

Does anyone know if/how this code can be adjusted to work on a generic
mailbox?

Thanks in advance...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Saving outlook attachments with VBA code

Sorry,

The problem is the inbox I am trying to save the attached files from.
Currently, I am able to save attachments from emails to my personal inbox,
but not from emails to the generic inbox (where the emails I want to save
attachments from actually arrive into). I currently have: Set Fldr =
olNs.GetDefaultFolder(olFolderInbox), but want to know if the default folder
can be set to a different, generic Mailbox inbox...

The code also fails every time it gets to the end of the loop, so I've had
to add a stupid errorhandler to stop the macro crashing each time. I think
it's something to do with the loop count, but don't know what... any help on
this would also be appreciated.

My actual code is:

Private Sub Workbook_Open()
Application.ScreenUpdating = False

Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As MailItem
Dim olAtt As Attachment
Dim MyPath As String
Dim i As Long

On Error GoTo ERRORHANDLER

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox) 'would like to change
this...
Set MoveToFldr = Fldr.Folders("2. STPM")
MyPath = "c:\WD forecasts\"

For i = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "Today's Trades") 0 Then
For Each olAtt In olMi.Attachments
olAtt.SaveAsFile MyPath & olAtt.Filename
Next olAtt
olMi.Save
olMi.Move MoveToFldr
End If
Next i

Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

closebook = MsgBox("Process Complete. Do you want to close this workbook?",
vbYesNo)
If closebook = vbYes Then
ActiveWorkbook.Close savechanges = False
End If
ERRORHANDLER:
closebook = MsgBox("Process complete (count failed after event). Do you want
to close this workbook?", vbYesNo)
If closebook = vbYes Then
ActiveWorkbook.Close savechanges = False
End If
Exit Sub

End Sub

"Jacob Skaria" wrote:

In the code the path mentioned is. Have you changed this and if so check
whether the path is a valid path and ends with "\"

MyPath = "C:\My Documents\Completed Survey\"

If this post helps click Yes
---------------
Jacob Skaria


"ewan7279" wrote:

Hi all,

I have my own outlook inbox and also a generic inbox I share with other
shift members. I have been able to save attachments from emails to my own
inbox using the code found at
http://www.dicks-clicks.com/excel/ol...ve_Attachments , but am
unable to do the same with my generic inbox - I get a message saying the
folder does not exist.

Does anyone know if/how this code can be adjusted to work on a generic
mailbox?

Thanks in advance...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Saving outlook attachments with VBA code

Is this generic ID setup in outlook or are you accessing this generic ID
using OWA.

(ToolsEmail accounts)

If this post helps click Yes
---------------
Jacob Skaria


"ewan7279" wrote:

Sorry,

The problem is the inbox I am trying to save the attached files from.
Currently, I am able to save attachments from emails to my personal inbox,
but not from emails to the generic inbox (where the emails I want to save
attachments from actually arrive into). I currently have: Set Fldr =
olNs.GetDefaultFolder(olFolderInbox), but want to know if the default folder
can be set to a different, generic Mailbox inbox...

The code also fails every time it gets to the end of the loop, so I've had
to add a stupid errorhandler to stop the macro crashing each time. I think
it's something to do with the loop count, but don't know what... any help on
this would also be appreciated.

My actual code is:

Private Sub Workbook_Open()
Application.ScreenUpdating = False

Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As MailItem
Dim olAtt As Attachment
Dim MyPath As String
Dim i As Long

On Error GoTo ERRORHANDLER

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox) 'would like to change
this...
Set MoveToFldr = Fldr.Folders("2. STPM")
MyPath = "c:\WD forecasts\"

For i = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "Today's Trades") 0 Then
For Each olAtt In olMi.Attachments
olAtt.SaveAsFile MyPath & olAtt.Filename
Next olAtt
olMi.Save
olMi.Move MoveToFldr
End If
Next i

Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

closebook = MsgBox("Process Complete. Do you want to close this workbook?",
vbYesNo)
If closebook = vbYes Then
ActiveWorkbook.Close savechanges = False
End If
ERRORHANDLER:
closebook = MsgBox("Process complete (count failed after event). Do you want
to close this workbook?", vbYesNo)
If closebook = vbYes Then
ActiveWorkbook.Close savechanges = False
End If
Exit Sub

End Sub

"Jacob Skaria" wrote:

In the code the path mentioned is. Have you changed this and if so check
whether the path is a valid path and ends with "\"

MyPath = "C:\My Documents\Completed Survey\"

If this post helps click Yes
---------------
Jacob Skaria


"ewan7279" wrote:

Hi all,

I have my own outlook inbox and also a generic inbox I share with other
shift members. I have been able to save attachments from emails to my own
inbox using the code found at
http://www.dicks-clicks.com/excel/ol...ve_Attachments , but am
unable to do the same with my generic inbox - I get a message saying the
folder does not exist.

Does anyone know if/how this code can be adjusted to work on a generic
mailbox?

Thanks in advance...

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Saving outlook attachments with VBA code

Sorry, not sure I understand the question...

I don't think it's an ID, it's just a mailbox in Outlook that only 5 people
have access to, in addition to our personal inboxes. It is in the same
format (contains the same folders etc) as my personal inbox, but I cannot add
anything to the calendar, all emails I send appear in my personal sent items,
and any emails I delete appear in my deleted items folder rather than the one
in the generic mailbox. I have the choice of sending emails from my own
email address or the generic mailbox address.

"Jacob Skaria" wrote:

Is this generic ID setup in outlook or are you accessing this generic ID
using OWA.

(ToolsEmail accounts)

If this post helps click Yes
---------------
Jacob Skaria


"ewan7279" wrote:

Sorry,

The problem is the inbox I am trying to save the attached files from.
Currently, I am able to save attachments from emails to my personal inbox,
but not from emails to the generic inbox (where the emails I want to save
attachments from actually arrive into). I currently have: Set Fldr =
olNs.GetDefaultFolder(olFolderInbox), but want to know if the default folder
can be set to a different, generic Mailbox inbox...

The code also fails every time it gets to the end of the loop, so I've had
to add a stupid errorhandler to stop the macro crashing each time. I think
it's something to do with the loop count, but don't know what... any help on
this would also be appreciated.

My actual code is:

Private Sub Workbook_Open()
Application.ScreenUpdating = False

Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As MailItem
Dim olAtt As Attachment
Dim MyPath As String
Dim i As Long

On Error GoTo ERRORHANDLER

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox) 'would like to change
this...
Set MoveToFldr = Fldr.Folders("2. STPM")
MyPath = "c:\WD forecasts\"

For i = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "Today's Trades") 0 Then
For Each olAtt In olMi.Attachments
olAtt.SaveAsFile MyPath & olAtt.Filename
Next olAtt
olMi.Save
olMi.Move MoveToFldr
End If
Next i

Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

closebook = MsgBox("Process Complete. Do you want to close this workbook?",
vbYesNo)
If closebook = vbYes Then
ActiveWorkbook.Close savechanges = False
End If
ERRORHANDLER:
closebook = MsgBox("Process complete (count failed after event). Do you want
to close this workbook?", vbYesNo)
If closebook = vbYes Then
ActiveWorkbook.Close savechanges = False
End If
Exit Sub

End Sub

"Jacob Skaria" wrote:

In the code the path mentioned is. Have you changed this and if so check
whether the path is a valid path and ends with "\"

MyPath = "C:\My Documents\Completed Survey\"

If this post helps click Yes
---------------
Jacob Skaria


"ewan7279" wrote:

Hi all,

I have my own outlook inbox and also a generic inbox I share with other
shift members. I have been able to save attachments from emails to my own
inbox using the code found at
http://www.dicks-clicks.com/excel/ol...ve_Attachments , but am
unable to do the same with my generic inbox - I get a message saying the
folder does not exist.

Does anyone know if/how this code can be adjusted to work on a generic
mailbox?

Thanks in advance...



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Saving outlook attachments with VBA code

I'm assuming that the generic inbox is a sibling folder to the default
inbox.

Try something like this to get at that other inbox, assuming the generic
inbox is named "Staff Inbox" in my example:
'------------------------------------
Set objInbox = olNs.GetDefaultFolder(olFolderInbox)
strFolderName = objInbox.Parent
Set objMailbox = olNS.Folders(strFolderName)
Set objStaffInbox = objMailbox.Folders("Staff Inbox")
'------------------------------------

Steve Yandl


"ewan7279" wrote in message
...
Hi all,

I have my own outlook inbox and also a generic inbox I share with other
shift members. I have been able to save attachments from emails to my own
inbox using the code found at
http://www.dicks-clicks.com/excel/ol...ve_Attachments , but
am
unable to do the same with my generic inbox - I get a message saying the
folder does not exist.

Does anyone know if/how this code can be adjusted to work on a generic
mailbox?

Thanks in advance...


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code for sending Outlook email with attachments using a list craig Excel Programming 1 December 13th 07 10:48 PM
Outlook attachments Frederick Lorca Excel Programming 2 February 25th 07 08:42 PM
Outlook attachments Frederick Lorca Excel Programming 0 February 25th 07 08:01 AM
saving Outlook attachments Steph[_3_] Excel Programming 1 July 18th 05 09:30 PM
Saving attachments from Outlook Jamie Excel Programming 5 May 17th 05 07:08 PM


All times are GMT +1. The time now is 05:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"