+ Reply to Thread
Results 1 to 21 of 21

Automatic E-mail - Use of hyperlink in cell to add attachment

  1. #1
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Automatic E-mail - Use of hyperlink in cell to add attachment

    Good Day Lads & Ladettes!

    Tried to solve this in another thread but it wasn't going anywhere.

    Below is my sub to send an automatic e-mail depending on the date in a Cell. Each row contains metadata about a file (a transmittal - PDF), and in column 'A' of that row it has a file number 'ENER-P12345-0413-001' which is also a hyperlink to the file in question. I'd like to use the hyperlink address stored in this cell to attach the file to them generated e-mail automatically. Does anyone know if this is possible? Or how to reference the hyperlink address stored within this cell?

    Many thanks to anyone who can solve this one - I figure the data must be stored in the cell somewhere so it should be possible, but I'm no whiz kid like you macroids out there!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Short answer... no you can't...

    You are using Shell Execute to send the email and this method can't handle attachments. This thread explains the problem and some solutions using CDO.

    You can also use Outlook (if you want)

    Please Login or Register  to view this content.
    Late binding:
    Please Login or Register  to view this content.
    In the rare case you wanted to know every possible thing to do with Outlook, here are the enumerations:

    Please Login or Register  to view this content.
    abousetta
    Last edited by abousetta; 04-09-2013 at 09:11 AM.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Hey,

    Thanks for the info!

    I can change the way I launch the e-mail, it'll take a bit of fiddling around but that can be done.

    Would you know if it would be possible to use the hyperlink address in the cell as the information for the attachment in the above method?

  4. #4
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    I'm going to post this here - This guy seems to be doing a similar thing, any way we could use this and apply it to the application I'm doing?

    http://stackoverflow.com/questions/5...-in-excel-cell

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    I haven't tried using a hyperlink before but the concept should be the same (or maybe not... gota test and see what happens). If you need to download first to the local computer then you can use the code provided here. You can then automate the process... download to computer, attach to email, send, delete file from computer.

    abousetta

    P.S. haven't looked yet at the other thread

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Do you mean something like this http://blog.contextures.com/archives...cel-hyperlink/

    abousetta

  7. #7
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Yeah, I mean something like that Thanks.

    I'm kind of rubbish at putting it in context though, and I'm having trouble changing the macro from a shell execute to the early or late binding like you had in your post. This is the problem with trying to create complex macros with no visual basic knowledge.
    As soon as it gets to the .To = part I get an error.
    If I post what code I have can you help me correct it please?

  8. #8
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Okay,

    Well I managed to change the execution of the e-mail with the late binding example you gave.

    This seems to be working fine, now all I have to do is work out how to exctract the hyperlink address from the cell and use that for the attachment path! Exciting

    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Maybe try:

    Please Login or Register  to view this content.
    with rng being the range in the excel sheet. I won't be able to test till tonight though.

    abousetta

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Hi,

    OK, I tested it with both a link to file on my local computer and a second link to a file on the internet. Both worked just fine so you should be good to go. Only thing I should mentioned is that you have to give time to download the file from the internet if that is where your files are stored.

    abousetta

  11. #11
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Hi Absouetta, Thanks for that!

    I can't seem to get this working though. If I post my code with your bit included could tell me where I'm going wrong?

    Please Login or Register  to view this content.
    Also the files will be in a folder on my computer so it should be fine speedwise. Thanks for the consideration though! And many thanks in advance guy, really appreciate it!
    Last edited by RichTea88; 04-10-2013 at 04:39 AM. Reason: Additional information

  12. #12
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    A range must be set:

    Please Login or Register  to view this content.
    Works for me now.

    abousetta

  13. #13
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Still not working, even with the range set.

    So confused...

    Getting this runtime error - -2147352567(80020009)

    Maybe the link to my file is too long?
    Last edited by RichTea88; 04-10-2013 at 04:59 AM.

  14. #14
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Which line is causing the problem? Maybe try using a file on a local drive with a shorter URL and walking through the code.

    abousetta

  15. #15
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    It's this line

    Please Login or Register  to view this content.
    I'm using a file on the desktop with a short url now, still getting the same problem. I've even tried using the get hyperlink as a function instead,but it just causes the same error. Maybe you have a reference library in use that I don't? Could you possibly paste the entire subroutine your using and I can try just replacing my one with it?

  16. #16
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Whats really annoying is that when I hover over the
    Please Login or Register  to view this content.
    it shows the correct file path to the pdf. It just comes up with that error and I don't know what to do to get past it.

  17. #17
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    This is actually driving me crazy. It just doesn't seem like the coding is wrong

  18. #18
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Change this from late binding to early binding. It still doesnt work, but it's went from being a runtime error to a compile error - 'Argument not optional' and it highlights this part '.Add ='

    If I remove the attachments line of code it works fine, so there's something wrong with this one line. I'll give rep to anyone who gives me any insight into why this isn't working, even if they're wrong because I'm out of ideas and I'd hate for a single line of coding to stop me solving this

  19. #19
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Solved!

    and yet not solved

    This is the corrected code
    Please Login or Register  to view this content.
    The problem - the workbook is in the same main folder as the files, but in different subfolders (if you get what I mean). Because excel shortens the hyperlink it means it won't work as an attachment. Is there anyway to have the hyperlinks as the full address?

    This code seems to work when the workbook is on my desktop and the hyperlink to the file is on a different drive.

  20. #20
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Solved! Code below.

    Not exactly the neatest way around it but it works! Pretty much had to set a constant for the address of the folder the files & workbook are kept in(FPath), then used the grab hyperlink (FName) to get the futher extension of folders and combined them to make another variable (Ease).

    As I said, not exactly the neatest way, but it works! Can I give Rep to myself? :P

    Please Login or Register  to view this content.
    A Big thanks to Abousetta for all his help! Cheers Dude!

  21. #21
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Automatic E-mail - Use of hyperlink in cell to add attachment

    Glad it worked out.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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