+ Reply to Thread
Results 1 to 18 of 18

why is the file name duplicating in subject field?

  1. #1
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    why is the file name duplicating in subject field?

    Hi there,

    I need some help with a VBA code and was wondering if anyone could help.

    I needed a VBA code to email a single excel sheet from a workbook and found the code below. The problem is that when the file gets emailed to the recipient, the file name says 'TestFileScottNew.xlsm.xlsm'. In other words, the 'xlsm' part gets duplicated in the attachment and I want to prevent this from happening. I was wondering if anyone could help and let me know how to remove one of the xlsm's in the file name? (if you have a better code to help me achieve my aim then feel free to suggest it!)

    Here is the code:

    Please Login or Register  to view this content.
    Any help appreciated!
    Last edited by ray707; 04-01-2021 at 05:03 PM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: why is the file name duplicating in subject field?

    Try...
    Please Login or Register  to view this content.
    ... and add code tags to your post.

  3. #3
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: why is the file name duplicating in subject field?

    change this line
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Quote Originally Posted by dangelor View Post
    Try...
    Please Login or Register  to view this content.
    ... and add code tags to your post.
    Quote Originally Posted by AC PORTA VIA View Post
    change this line
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    That worked! Thank you!

    The only thing is the file name now has 'temp' at the beginning, so it says 'TempTestFileScottNew.xlsm'- this is less of a problem but any ideas why and how to fix it?!

    also how can I put this into a command button so that the user can press a button and it pings out the email? I tried putting the above into the VBA for a command button but it didn't work:

    Please Login or Register  to view this content.
    The error says:

    Compile error: expected end sub
    Last edited by ray707; 04-01-2021 at 05:32 PM.

  5. #5
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: why is the file name duplicating in subject field?

    remove below line
    Please Login or Register  to view this content.

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: why is the file name duplicating in subject field?

    The only thing is the file name now has 'temp' at the beginning, so it says 'TempTestFileScottNew.xlsm'- this is less of a problem but any ideas why and how to fix it?!
    Try this...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Quote Originally Posted by dangelor View Post
    Try this...
    Please Login or Register  to view this content.
    This didn't work for removing 'temp'; it would send an email without an attachment and before that it would ask me to save the file which I want to avoid...

  8. #8
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Quote Originally Posted by AC PORTA VIA View Post
    remove below line
    Please Login or Register  to view this content.
    This worked for the command button, thank you. It does generate a pop up notification upon activation though which says 'A file named C:\Users\xxxx\AppData\Local\TempBook1.xlsm already exists in this location. Do you want to replace it?' but I think that is okay, right? My understanding is that the way these codes work is that they create a temp file in a location and then deletes it, so this is simply doing that..? Therefore I don't think we can avoid this can we..?
    Last edited by ray707; 04-02-2021 at 04:05 AM.

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: why is the file name duplicating in subject field?

    Try this version...
    Please Login or Register  to view this content.
    Last edited by dangelor; 04-02-2021 at 08:12 AM.

  10. #10
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Quote Originally Posted by dangelor View Post
    try this version...
    Please Login or Register  to view this content.
    thank you!

  11. #11
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Hello, I have a quick question about the code posted by dangelor 2 posts above. I want to amend this code to send out the email to an address in a specific cell in that worksheet; so for example, if I write an email address in cell D2 of the worksheet, I want the code to send the sheet to that email address. I thought I could do this by simple amending the .To part of the code:


    Please Login or Register  to view this content.
    However this did not work and no email was sent out. Please can someone advise?
    Last edited by ray707; 04-14-2021 at 05:48 AM.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: why is the file name duplicating in subject field?

    Are you sure the codename of your sheet is Sheet1?
    Everyone who confuses correlation and causation ends up dead.

  13. #13
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Quote Originally Posted by rorya View Post
    Are you sure the codename of your sheet is Sheet1?
    In the actual excel file the sheet is called 'Craft summary' and in the visual basic under Microsoft Excel Objects it says 'Sheet1 (Craft summary)'. Am I inputting the name incorrectly for the sheet?

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: why is the file name duplicating in subject field?

    And that is the workbook with the code in it?

  15. #15
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    I got it working! I transferred the code from module to worksheet and that worked. Perhaps I need to improve my understanding of module vs worksheet as I thought it was always best to put the code in the module

    Thanks!
    Last edited by ray707; 04-14-2021 at 08:10 AM.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,991

    Re: why is the file name duplicating in subject field?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  17. #17
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    Hi guys, quick question.

    If I want the text in the body of the email to reference a cell in the excel sheet, how would I do that?

    So for example, if the job number is in cell A9, and I want the text in the email body to say 'please find spreadsheet attached for A9', how would I amend the code?

    Please Login or Register  to view this content.
    Any help would be appreciated

  18. #18
    Registered User
    Join Date
    04-01-2021
    Location
    United Kingdom
    MS-Off Ver
    2018
    Posts
    17

    Re: why is the file name duplicating in subject field?

    hmmm the code to send out an email is not working now, I am not sure why. Does anyone have any idea why? When I click on the command button to send the email it creates a new file with that worksheet in it and nothing gets emailed. This didn't happen usually, it would just send that worksheet out automatically (no new file was created or anything, it would get emailed straight out to the recipient)

    Please Login or Register  to view this content.


    EDIT: The code works now so this post is redundant. If anyone can help with the post above that would be great
    Last edited by ray707; 04-29-2021 at 10:24 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. Populate Subject Line if the "To" Field belongs to a specific Recipient
    By RXcel in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 10-06-2019, 03:04 AM
  2. Replies: 17
    Last Post: 01-12-2018, 12:57 PM
  3. [SOLVED] Help comparing two files by subject+Date, subject+DatePlus1, Subject+DateMinus1
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-11-2017, 07:37 AM
  4. [SOLVED] Todays date in subject field of mailto hyperlink formula
    By ayz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-29-2016, 08:30 AM
  5. Save outlook attachment as file using email subject as file name w/o invalid characters
    By kristinlarmer in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 10-16-2015, 05:07 PM
  6. [SOLVED] Pivot tables duplicating one field
    By ctone51 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 03-23-2014, 02:02 AM
  7. Duplicating rows and doing calculations based on a field
    By Iceotron in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2012, 02:48 AM

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