3

The code below saves the attachments [to "My Documents" folder] of "selected" emails in Outlook.

Can you please advise how to change the location of the sFolderPath = objWSCript.specialfolders(16) to a "New Folder" folder on C drive ?

Option Explicit

Sub SaveAttchFiles()

Dim olMail As MailItem
Dim olAtchs As Attachments
Dim olSelection As Selection
Dim iCount As Long, i As Long
Dim sFolderPath As String, sFilePath As String, sDeletedFiles As String
Dim objWSCript As Object

On Error Resume Next

Set objWSCript = CreateObject("WSCript.Shell")

sFolderPath = objWSCript.specialfolders(16)

Set olSelection = ActiveExplorer.Selection

sFolderPath = sFolderPath & "\New Folder\"

For Each olMail In olSelection

Set olAtchs = olMail.Attachments
iCount = olAtchs.Count
sDeletedFiles = ""

If iCount > 0 Then
For i = iCount To 1 Step -1
sFilePath = sFolderPath & olAtchs.Item(i).FileName
olAtchs.Item(i).SaveAsFile sFilePath

Next i
End If


Next olMail

Door:

Set objWSCript = Nothing
Set olAtchs = Nothing
Set olSelection = Nothing

End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
Alien_Explorer
  • 859
  • 1
  • 9
  • 22

1 Answers1

4

Really? You have a folder called New Folder? And it's in another folder called All Folders? boy oh boy....

Anyhow, if that's really the case then you only need to change:

sFolderPath = sFolderPath & "\New Folder\"

...to...

sFolderPath = "C:\All Folders\New Folder\"

As a bonus, check out:

ashleedawg
  • 20,365
  • 9
  • 72
  • 105