Save attachment In sub folder

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Save attachment In sub folder

Post by Nabeel »

Hello All
I want to save outlook attachments auto create subfolder with the name of mail subject in main folder.
Code should like by selecting mails either single or multiple.
I made lots google searches butt didn't find any solution
Any possibility or suggestion
Nabeel

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

See 32/64-bit compatible version of Outlook Attachment Manager for a zip file with code that removes attachments from email messages and saves them in a folder. The code could be modified to save the attachments to a folder named after the subject of the message.
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

i unzipped the file & follow the instruction as mention, some of issues
code is showing red highlighted some area, i think below code is repeating & i deleted repeated part but still in red
basCallBacks.JPG
below is three red highlighted (different location)in code
Seond Red.JPG


& sir, i am not a proficient to change in VBA (how & where) :hairout: :hairout:
You do not have the required permissions to view the files attached to this post.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Save attachment In sub folder

Post by Rudi »

Instead of 'importing' the individual bas and frm modules, just drag them into the VbaProject.OTM directly from Windows Explorer.

Open Outlook and access the VBA window (ALT + F11)
Then open Windows Explorer and drag the files onto the VbaProject.OTM (see image below)

The 3 forms and the 2 modules will be added to the project.
You do not need to edit any code as it will import without issues.

You can use the macro by running the frmAttachmentManager.frm or follow the rest of the instructions to add a button to the Quick Access Toolbar.
20180312_57.jpg
This is what the VBA Project will look like after ta correct import.
20180312_58.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

thanks for help now this is as like as you say
some of part still in RED but code is working fine i run,
Capture.JPG
need amendment that attachment save in sub folder which auto create with the name of mail subject with multi selection of mail, Right now this is only saving one mail attachment if select 4 to 5 mails(multi selection means all selected mails create its own sub folder not all selected in one) & i just need attachment which is sender attached, not body mail attachment like logo, icon of twitter FB address ect..
please help

Nabeel
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

I don't think Outlook distinguishes between different types of attachments. In other words, we don't know if an attachment is a logo or icon, or a file attached explicitly by the sender.
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

hmm,i mean logo or ican in body mail under signature ect like below, there is an option in your code to unselect i can go with it, can you modify code for subfolder and with multi selection as stated in last my post, please
Capture.PNG
Rgd's
Nabeel
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

I'll have a look later on, it's complicated.
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

thanks sir for this, i really appreciate your any help regarding this..!

Rgd's
Nabeel

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

Here is a zip file with a new version. It creates subfolders in the user's Documents folder, but you can change that if you like by editing the line

Code: Select all

  strMainFolder = CreateObject("Wscript.Shell").SpecialFolders("MyDocuments") & "\"
Remove the previous modules and userforms, then drag the module and the two userforms into the Project Explorer in the Visual Basic Editor.

StartAttachmentManager is still the macro to call.
SaveAttachments.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

this is superb sir, outclass stuff, you are master class :clapping: :clapping: :clapping:
i want to change the path where i place this line, please guide i want to make path C:\Users\nabeel.akhtar1\Desktop\NP\

Nabeel

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

Simply change the line

Code: Select all

  strMainFolder = CreateObject("Wscript.Shell").SpecialFolders("MyDocuments") & "\"
to

Code: Select all

  strMainFolder = "C:\Users\nabeel.akhtar1\Desktop\NP\"
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

i didn't find this mention line in code at basattmat module.

Code: Select all

strMainFolder = CreateObject("Wscript.Shell").SpecialFolders("MyDocuments") & "\"
Nabeel

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

The line is in the code of the userform frmAttachmentManager.
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

hurray hurray hurray sweet hug sir :grin: :grin:
thnx a lot sir, you make my work soo easy in fact now it will be in minutes :thankyou: :thankyou: :thankyou: :thankyou:
May God bless you with health
Nabeel

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

Hi sir
i am here again with some issue, i selected almost 55 mails and run code, code shows me below error
Capture a.JPG
& when i click on debug that bring me here
Capture 1.JPG
if this is due to duplication of subject (which is my thought) code should kept all duplicates..!
Nabeel
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

I hadn't taken into account that the subject would end in a long number. See if this works better:

Code: Select all

Public Function funcSuggestName(strT As String) As String
  Dim intL As Integer
  Dim intC As Integer
  Dim intP As Integer
  Dim intN As Integer
  Dim strQ As String
  Dim strX As String
  Dim strN As String
  Dim str_ As String
  Dim boolNum As Boolean
  funcSuggestName = strT
  Do
    intP = InStrRev(funcSuggestName, ".")
    If intP = 0 Then
      strQ = funcSuggestName
    Else
      strQ = Left(funcSuggestName, intP - 1)
      strX = Mid(funcSuggestName, intP)
    End If
    intL = Len(strQ)  ' string length without the extension
    For intC = intL To 1 Step -1
      intN = Asc(Mid(strQ, intC, 1))
      If intN < 48 Or intN > 57 Then
        Exit For
      End If
    Next intC
    If intC = intL Then
      strQ = strQ & "_1"
    ElseIf intL - intC < 9 Then
      strQ = Left(strQ, intC) & (CLng(Mid(strQ, intC + 1)) + 1)
    Else
      strQ = strQ & "_" & Int(100 * Timer)
    End If
    funcSuggestName = strQ & strX
    DoEvents
  Loop Until NoDupFileExists(funcSuggestName)
End Function
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

now its shows me duplicate file window, here asking for file name change one by one for all, than saving all the files in that one folder, isn't required this to me.
just want, it should allow folder name change once for each folder(irrespective of how many attachments are under it & do not ask for file name change under folder)than save attachment in it or auto rename folder like under

if subject is
SOHO-7102-03018240182
than
SOHO-7102-03018240182-001
SOHO-7102-03018240182-002
SOHO-7102-03018240182-003
Rgd's
Nabeel

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save attachment In sub folder

Post by HansV »

Do you want to save attachments from different messages with the same subject in different folders?
Best wishes,
Hans

Nabeel
2StarLounger
Posts: 170
Joined: 26 Jan 2017, 07:24

Re: Save attachment In sub folder

Post by Nabeel »

for only which has same subject mails other than code is okay.!
code is working fine i observed that only error occur when their is two or three mails are with same subject.
for example
if i received 6 mails with below same subject
SOHO-7102-03018240182
than 6 sub folders will create & each folder will contain their attachment
SOHO-7102-03018240182-001
SOHO-7102-03018240182-002
SOHO-7102-03018240182-003
SOHO-7102-03018240182-004
SOHO-7102-03018240182-005
SOHO-7102-03018240182-006
Rgd's
Nabeel