+ Reply to Thread
Results 1 to 26 of 26

attach a file automatically to outlook email

  1. #1
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    attach a file automatically to outlook email

    Hello, I have tried to add a file as an attachment. I have the path and want part of the file name to be from column B in a excel spreadsheet.7

    Only part of the filename to be searched for and then all files with that data from column B in their filename attached to the email.
    In column B it wold be a 5 digit number re.g 41532 and the filename would start T41532

    Please Login or Register  to view this content.
    Thank you or any help provided
    Last edited by UltimateNeo; 09-28-2019 at 03:39 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Perhaps...Untested
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    Hello I tried your code, but get a runtime 438 error object doesn't support this property or method.

    on the

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Post all your code....And a sample of your exact setup...

  5. #5
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    It is just a basic email, attaching the pdf file that has a filename of T41234 - name - initials.

    In excel sheet column B I have the T41234 without the T as the T is put in the subject line of the email.

    Please Login or Register  to view this content.

    Thank you for your help

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    "C:\mypath\"
    This is from Post 1...Why change to
    Please Login or Register  to view this content.
    Is there a file to be added at that specific path...
    Declaration as per below means...Path is declared as a variant, File as string
    Have to specify...
    Please Login or Register  to view this content.
    And it is...
    Please Login or Register  to view this content.
    Sorry did not pick up earlier...
    Last edited by Sintek; 09-28-2019 at 01:18 PM.

  7. #7
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    Thank you I changed the code as you stated but it cant find the file pat his correct and file is there I changed the name from T54321 to 54321to see if that helps but it still cant verify and find the file

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    hat helps but it still cant verify and find the file
    Then it is not where the path says it is...
    Right click on file and check properties...See if path is as per coded path...

    These are also not specified...
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    I got it to find the file when I rename the file 54321, But it wont find it if I call it T54321

    Please Login or Register  to view this content.
    Thank you for your help

  10. #10
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    It also seems to just check row 3.

    I made a file called 34212 and it finds that one but if I go to next row with 54321 it ill not find it, just opens with 34212

    So it only finds the first file not moving to the next row for the different named file

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Perhaps you should upload file...
    Check your value of lastrow...make sure it is not 3...
    Please Login or Register  to view this content.
    Last edited by Sintek; 09-28-2019 at 01:54 PM.

  12. #12
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    The name of the file is T54321 and in the Sheets("Estimate").Range("B" & CustRow) is 54321 so without the t

    Thanks

  13. #13
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    full filename will be T54321 - name - intial.pdf if that helps I just want to find the number part in the filename as hat should be unique.

    Think of the T54321 as a quote number for a job to a customer if that helps

  14. #14
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Post 9 code is not the issue...
    You say it is not looping through all...

  15. #15
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    I have attached a file
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    code is in the forms estimate in the vba

  17. #17
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    That helps nothing...No info in sheet...

    What is the actual issue now...
    The code works but does not attach the file...Your path is incorrect or the file is not at the specified path...
    The code only works for the first loop...then your lastrow is incorrect as it starts from 3 to lastrow...

  18. #18
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    The code can only find the file if the file name is e.g 34212 not if that is just a part of the file name full file name would be T34212 - company name - tech initials.Pdf

    The Tno is just part of the overall file name.

  19. #19
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    file name would be T34212 - company name - tech initials.Pdf
    If this is the case then your code has to be set up too find the file...
    This cell which this code refers to...
    Please Login or Register  to view this content.
    must have this value..."34212 - company name - tech initials"

    I cannot assist because you uploaded a file without info and I do not have the specific files saved to the specific path...
    Edit
    Upload a file with at least 3 values in the Estimate sheet and give me the names of those 3 files found in the actual path
    Last edited by Sintek; 09-29-2019 at 06:33 AM.

  20. #20
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    I have uploaded the file with 3 Tnos in the estimate 34212, 54321, 67890

    In the location "C:\Users\Bertie\Documents" are 3 files called T34212 - Cummins - DS.pdf, T54321 - T54321 - Argos - MD.pdf and T67890 - Argos - WD.pdf


    hope that helps thank you for your time.
    Attached Files Attached Files

  21. #21
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Well now this makes sense...
    How are you expecting to attach a file if your coded file name does not correspond...i.e.
    T34212 - Cummins - DS.pdf
    If the value in columns B is only the first numerical part...i.e. "34212"
    Where do you code the rest of the filename...i.e. "- Cummins - DS" etc
    Last edited by Sintek; 09-29-2019 at 07:00 AM.

  22. #22
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Re: attach a file automatically to outlook email

    I was hoping just to do the partial find, rather than the full file name, as to save time in inputing data. The T is added in the subject through the code. I was hoping to do something similar.

    It looks like your telling me best way is to have the whole file name.

    I thought I might be able to use wildcards or something?

  23. #23
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Full file name in path or you'll have to loop through all files and find file like "T41234*.pdf"

  24. #24
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209
    Quote Originally Posted by sintek View Post
    Full file name in path or you'll have to loop through all files and find file like "T41234*.pdf"
    Oh ok thank you i think i have an idea

  25. #25
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    Good luck...
    My suggestion...Have the rest of the file name stored in a cell and build string...Why would you want to loop all files in folder

  26. #26
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: attach a file automatically to outlook email

    This solves...If you wanna go wildcard option...
    Please Login or Register  to view this content.
    Last question...Why are you adding spaces this way..
    ."&nbsp"
    Last edited by Sintek; 09-29-2019 at 07:50 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using .attachments.add to attach an excel file to an outlook email
    By mirandajean in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-19-2017, 11:48 AM
  2. [SOLVED] Problem with VBA code to attach file to email using a pre saved Outlook template
    By Wooltrain in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-12-2017, 08:28 PM
  3. attach file in an outlook email from specific folder
    By 9599lorenzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2017, 07:07 AM
  4. Attach new excel automatically with file format change through outlook
    By Ravipoojari in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2015, 09:07 AM
  5. [SOLVED] Macro to attach an additional file to and outlook email
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2014, 01:27 PM
  6. Zip file and attach to email automatically
    By mhart210 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2006, 01:29 PM
  7. Automatically attach Excel spreadsheet to Outlook Email with Macro?
    By nbaj2k in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-01-2006, 11:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1