Extracting Attachments from *.msg files stored in many subfolders within main Shared Folder
up vote
0
down vote
favorite
I'm seeking your kind support to revise the below code to extract Attachments from *.msg files stored in many subfolders within main Shared Folder.
The below code is working fine for *.msg files if stored in one folder, but can't work for *.msg files stored in the subfolders.
The path for the main Folder is:
U:XXXXXXXXXXMain Folder
The paths for the subfolders are:
U:XXXXXXXXXXMain FolderFolder1
U:XXXXXXXXXXMain FolderFolder2
U:XXXXXXXXXXMain FolderFolder3
..etc.
Below is the code:
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
'path for saving attachments
strAttPath = "DAttachments"
strFile = Dir(strFilePath & "*.msg")
Do While Len(strFile) > 0
Set msg = Application.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
strFile = Dir
Loop
End Sub
vba outlook-vba email-attachments subfolder msg
add a comment |
up vote
0
down vote
favorite
I'm seeking your kind support to revise the below code to extract Attachments from *.msg files stored in many subfolders within main Shared Folder.
The below code is working fine for *.msg files if stored in one folder, but can't work for *.msg files stored in the subfolders.
The path for the main Folder is:
U:XXXXXXXXXXMain Folder
The paths for the subfolders are:
U:XXXXXXXXXXMain FolderFolder1
U:XXXXXXXXXXMain FolderFolder2
U:XXXXXXXXXXMain FolderFolder3
..etc.
Below is the code:
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
'path for saving attachments
strAttPath = "DAttachments"
strFile = Dir(strFilePath & "*.msg")
Do While Len(strFile) > 0
Set msg = Application.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
strFile = Dir
Loop
End Sub
vba outlook-vba email-attachments subfolder msg
stackoverflow.com/questions/20687810/…
– Tim Williams
Jan 11 at 6:39
Thanks a lot Tim for your prompt response. Much appreciated. As my VBA knowledge is limited, can you do me a favor & combine the two code together. Thank you again Tim :)
– Obada Talal
Jan 11 at 6:54
Possible duplicate of VBA macro that search for file in multiple subfolders
– F0XS
Jan 11 at 6:55
Thank you FoxCy. I would be grateful if the codes can be combined together to extract all the attachments from the resulted *.msg files. Appreciated.
– Obada Talal
Jan 11 at 7:08
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm seeking your kind support to revise the below code to extract Attachments from *.msg files stored in many subfolders within main Shared Folder.
The below code is working fine for *.msg files if stored in one folder, but can't work for *.msg files stored in the subfolders.
The path for the main Folder is:
U:XXXXXXXXXXMain Folder
The paths for the subfolders are:
U:XXXXXXXXXXMain FolderFolder1
U:XXXXXXXXXXMain FolderFolder2
U:XXXXXXXXXXMain FolderFolder3
..etc.
Below is the code:
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
'path for saving attachments
strAttPath = "DAttachments"
strFile = Dir(strFilePath & "*.msg")
Do While Len(strFile) > 0
Set msg = Application.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
strFile = Dir
Loop
End Sub
vba outlook-vba email-attachments subfolder msg
I'm seeking your kind support to revise the below code to extract Attachments from *.msg files stored in many subfolders within main Shared Folder.
The below code is working fine for *.msg files if stored in one folder, but can't work for *.msg files stored in the subfolders.
The path for the main Folder is:
U:XXXXXXXXXXMain Folder
The paths for the subfolders are:
U:XXXXXXXXXXMain FolderFolder1
U:XXXXXXXXXXMain FolderFolder2
U:XXXXXXXXXXMain FolderFolder3
..etc.
Below is the code:
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
'path for saving attachments
strAttPath = "DAttachments"
strFile = Dir(strFilePath & "*.msg")
Do While Len(strFile) > 0
Set msg = Application.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
strFile = Dir
Loop
End Sub
vba outlook-vba email-attachments subfolder msg
vba outlook-vba email-attachments subfolder msg
edited Jan 11 at 9:07
0m3r
7,52392353
7,52392353
asked Jan 11 at 6:29
Obada Talal
32
32
stackoverflow.com/questions/20687810/…
– Tim Williams
Jan 11 at 6:39
Thanks a lot Tim for your prompt response. Much appreciated. As my VBA knowledge is limited, can you do me a favor & combine the two code together. Thank you again Tim :)
– Obada Talal
Jan 11 at 6:54
Possible duplicate of VBA macro that search for file in multiple subfolders
– F0XS
Jan 11 at 6:55
Thank you FoxCy. I would be grateful if the codes can be combined together to extract all the attachments from the resulted *.msg files. Appreciated.
– Obada Talal
Jan 11 at 7:08
add a comment |
stackoverflow.com/questions/20687810/…
– Tim Williams
Jan 11 at 6:39
Thanks a lot Tim for your prompt response. Much appreciated. As my VBA knowledge is limited, can you do me a favor & combine the two code together. Thank you again Tim :)
– Obada Talal
Jan 11 at 6:54
Possible duplicate of VBA macro that search for file in multiple subfolders
– F0XS
Jan 11 at 6:55
Thank you FoxCy. I would be grateful if the codes can be combined together to extract all the attachments from the resulted *.msg files. Appreciated.
– Obada Talal
Jan 11 at 7:08
stackoverflow.com/questions/20687810/…
– Tim Williams
Jan 11 at 6:39
stackoverflow.com/questions/20687810/…
– Tim Williams
Jan 11 at 6:39
Thanks a lot Tim for your prompt response. Much appreciated. As my VBA knowledge is limited, can you do me a favor & combine the two code together. Thank you again Tim :)
– Obada Talal
Jan 11 at 6:54
Thanks a lot Tim for your prompt response. Much appreciated. As my VBA knowledge is limited, can you do me a favor & combine the two code together. Thank you again Tim :)
– Obada Talal
Jan 11 at 6:54
Possible duplicate of VBA macro that search for file in multiple subfolders
– F0XS
Jan 11 at 6:55
Possible duplicate of VBA macro that search for file in multiple subfolders
– F0XS
Jan 11 at 6:55
Thank you FoxCy. I would be grateful if the codes can be combined together to extract all the attachments from the resulted *.msg files. Appreciated.
– Obada Talal
Jan 11 at 7:08
Thank you FoxCy. I would be grateful if the codes can be combined together to extract all the attachments from the resulted *.msg files. Appreciated.
– Obada Talal
Jan 11 at 7:08
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Using my answer from VBA macro that search for file in multiple subfolders
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
Dim colFiles As New Collection, f
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
GetFiles strFilePath , "*.msg", True, colFiles
'path for saving attachments
strAttPath = "DAttachments"
For Each f in colFiles
Set msg = Application.CreateItemFromTemplate(f)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
Next
End Sub
Sub to perform the search:
Sub GetFiles(StartFolder As String, Pattern As String, _
DoSubfolders As Boolean, ByRef colFiles As Collection)
Dim f As String, sf As String, subF As New Collection, s
If Right(StartFolder, 1) <> "" Then StartFolder = StartFolder & ""
f = Dir(StartFolder & Pattern)
Do While Len(f) > 0
colFiles.Add StartFolder & f
f = Dir()
Loop
sf = Dir(StartFolder, vbDirectory)
Do While Len(sf) > 0
If sf <> "." And sf <> ".." Then
If (GetAttr(StartFolder & sf) And vbDirectory) <> 0 Then
subF.Add StartFolder & sf
End If
End If
sf = Dir()
Loop
For Each s In subF
GetFiles CStr(s), Pattern, True, colFiles
Next s
End Sub
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Did you copy theGetFilessub from the linked question? I've added it above.
– Tim Williams
Jan 12 at 6:23
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Using my answer from VBA macro that search for file in multiple subfolders
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
Dim colFiles As New Collection, f
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
GetFiles strFilePath , "*.msg", True, colFiles
'path for saving attachments
strAttPath = "DAttachments"
For Each f in colFiles
Set msg = Application.CreateItemFromTemplate(f)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
Next
End Sub
Sub to perform the search:
Sub GetFiles(StartFolder As String, Pattern As String, _
DoSubfolders As Boolean, ByRef colFiles As Collection)
Dim f As String, sf As String, subF As New Collection, s
If Right(StartFolder, 1) <> "" Then StartFolder = StartFolder & ""
f = Dir(StartFolder & Pattern)
Do While Len(f) > 0
colFiles.Add StartFolder & f
f = Dir()
Loop
sf = Dir(StartFolder, vbDirectory)
Do While Len(sf) > 0
If sf <> "." And sf <> ".." Then
If (GetAttr(StartFolder & sf) And vbDirectory) <> 0 Then
subF.Add StartFolder & sf
End If
End If
sf = Dir()
Loop
For Each s In subF
GetFiles CStr(s), Pattern, True, colFiles
Next s
End Sub
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Did you copy theGetFilessub from the linked question? I've added it above.
– Tim Williams
Jan 12 at 6:23
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
add a comment |
up vote
0
down vote
accepted
Using my answer from VBA macro that search for file in multiple subfolders
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
Dim colFiles As New Collection, f
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
GetFiles strFilePath , "*.msg", True, colFiles
'path for saving attachments
strAttPath = "DAttachments"
For Each f in colFiles
Set msg = Application.CreateItemFromTemplate(f)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
Next
End Sub
Sub to perform the search:
Sub GetFiles(StartFolder As String, Pattern As String, _
DoSubfolders As Boolean, ByRef colFiles As Collection)
Dim f As String, sf As String, subF As New Collection, s
If Right(StartFolder, 1) <> "" Then StartFolder = StartFolder & ""
f = Dir(StartFolder & Pattern)
Do While Len(f) > 0
colFiles.Add StartFolder & f
f = Dir()
Loop
sf = Dir(StartFolder, vbDirectory)
Do While Len(sf) > 0
If sf <> "." And sf <> ".." Then
If (GetAttr(StartFolder & sf) And vbDirectory) <> 0 Then
subF.Add StartFolder & sf
End If
End If
sf = Dir()
Loop
For Each s In subF
GetFiles CStr(s), Pattern, True, colFiles
Next s
End Sub
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Did you copy theGetFilessub from the linked question? I've added it above.
– Tim Williams
Jan 12 at 6:23
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Using my answer from VBA macro that search for file in multiple subfolders
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
Dim colFiles As New Collection, f
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
GetFiles strFilePath , "*.msg", True, colFiles
'path for saving attachments
strAttPath = "DAttachments"
For Each f in colFiles
Set msg = Application.CreateItemFromTemplate(f)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
Next
End Sub
Sub to perform the search:
Sub GetFiles(StartFolder As String, Pattern As String, _
DoSubfolders As Boolean, ByRef colFiles As Collection)
Dim f As String, sf As String, subF As New Collection, s
If Right(StartFolder, 1) <> "" Then StartFolder = StartFolder & ""
f = Dir(StartFolder & Pattern)
Do While Len(f) > 0
colFiles.Add StartFolder & f
f = Dir()
Loop
sf = Dir(StartFolder, vbDirectory)
Do While Len(sf) > 0
If sf <> "." And sf <> ".." Then
If (GetAttr(StartFolder & sf) And vbDirectory) <> 0 Then
subF.Add StartFolder & sf
End If
End If
sf = Dir()
Loop
For Each s In subF
GetFiles CStr(s), Pattern, True, colFiles
Next s
End Sub
Using my answer from VBA macro that search for file in multiple subfolders
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
Dim colFiles As New Collection, f
'path for msgs
strFilePath = "U:XXXXXXXXXXMain Folder"
GetFiles strFilePath , "*.msg", True, colFiles
'path for saving attachments
strAttPath = "DAttachments"
For Each f in colFiles
Set msg = Application.CreateItemFromTemplate(f)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
Next
End Sub
Sub to perform the search:
Sub GetFiles(StartFolder As String, Pattern As String, _
DoSubfolders As Boolean, ByRef colFiles As Collection)
Dim f As String, sf As String, subF As New Collection, s
If Right(StartFolder, 1) <> "" Then StartFolder = StartFolder & ""
f = Dir(StartFolder & Pattern)
Do While Len(f) > 0
colFiles.Add StartFolder & f
f = Dir()
Loop
sf = Dir(StartFolder, vbDirectory)
Do While Len(sf) > 0
If sf <> "." And sf <> ".." Then
If (GetAttr(StartFolder & sf) And vbDirectory) <> 0 Then
subF.Add StartFolder & sf
End If
End If
sf = Dir()
Loop
For Each s In subF
GetFiles CStr(s), Pattern, True, colFiles
Next s
End Sub
edited Jan 12 at 6:24
answered Jan 11 at 18:04
Tim Williams
83.7k96481
83.7k96481
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Did you copy theGetFilessub from the linked question? I've added it above.
– Tim Williams
Jan 12 at 6:23
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
add a comment |
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Did you copy theGetFilessub from the linked question? I've added it above.
– Tim Williams
Jan 12 at 6:23
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Thanks a lot Tim for your efforts. I tried the code but I'm getting Compile error, Sub or Function not defined. Any thoughts from your side?
– Obada Talal
Jan 12 at 5:59
Did you copy the
GetFiles sub from the linked question? I've added it above.– Tim Williams
Jan 12 at 6:23
Did you copy the
GetFiles sub from the linked question? I've added it above.– Tim Williams
Jan 12 at 6:23
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
It worked amazingly! Thank you so much Tim. Wish you all the best in your life & career. Have a great day ahead!
– Obada Talal
Jan 16 at 5:03
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48201007%2fextracting-attachments-from-msg-files-stored-in-many-subfolders-within-main-sh%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/20687810/…
– Tim Williams
Jan 11 at 6:39
Thanks a lot Tim for your prompt response. Much appreciated. As my VBA knowledge is limited, can you do me a favor & combine the two code together. Thank you again Tim :)
– Obada Talal
Jan 11 at 6:54
Possible duplicate of VBA macro that search for file in multiple subfolders
– F0XS
Jan 11 at 6:55
Thank you FoxCy. I would be grateful if the codes can be combined together to extract all the attachments from the resulted *.msg files. Appreciated.
– Obada Talal
Jan 11 at 7:08