+ Reply to Thread
Results 1 to 3 of 3

***Wrong sheet gets pasted in the outlook mail***

  1. #1
    Spammer
    Join Date
    06-27-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    183

    Thumbs up ***Wrong sheet gets pasted in the outlook mail***

    Hi Friends,

    I have twice posted this query but still unsolved

    The change I required is, I am sending mails for some of the email id by attaching particular sheet and pasting the sheets in the body of the mail (As per existing VBA script)

    Here I am facing some problem, if the particular sheet is not in the work book, it is taking previously copies sheet and pasting in the body of the mail.

    I have two sheet in the work book (Sheet1 & Sheet2) and I am sending mails to two mail id

    1 mail: to [email protected] need to paste sheet 1 and sheet 2. Since both sheets are there in the work book it is pasting correctly

    2nd Mail: to [email protected] need to paste sheet 9 and sheet2. Since Sheet 9 is not in the work book it is wrongly pasting sheet 1. My requirement is if the mentioned sheet is not in the work book VBA should not paste anything and should be blank. Hence mail to [email protected] should paste only sheet 2.

    Kindly help to modify if the sheet is not exist in the work book, it should not copy previously copied sheet. I have attached the macro workbook for your reference.

    Regards,
    Prabhu
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: ***Wrong sheet gets pasted in the outlook mail***

    Hi,

    I'm not quite sure why you email macro needs to repeat some of the lines, and no doubt that could be tidied up. However perhaps the most logical way would be to Dim a variable that says whether Sheet9 is present and then set the variable accordingly, i.e.

    Dim sht9 As Boolean
    Dim ws As Worksheet

    Please Login or Register  to view this content.
    Then in the second part of your emailing macro after you've set rng in the With Sheets("Sheet9") block use the following instead

    Please Login or Register  to view this content.
    Incidentally it's much better practice to use VBA code names for sheets rather than sheet tab names. Some day you'll come unstuck when a user decides to change a sheet tab name.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: ***Wrong sheet gets pasted in the outlook mail***

    The first thing you should do is remove the On Error stuff like this.
    Please Login or Register  to view this content.
    Then I would suggest you don't repeat the same code twice, including the RangeToHTML function.
    If posting code please use code tags, see here.

  4. #4
    Spammer
    Join Date
    06-27-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    183

    Re: ***Wrong sheet gets pasted in the outlook mail***

    Hi Richard,

    I have very little knowledge in the VBA.

    Could you plz incorporate the changes in the Excel. I have tries but unable to update.

+ 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. VBA to copy sheet and mail with Outlook
    By riteoh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2013, 09:46 PM
  2. macro to copy graphs from excel sheet to outlook mail
    By kmksprasad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2013, 01:24 PM
  3. Programming outlook mail Excel sheet
    By Quintusss in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2012, 12:46 AM
  4. macro for sendding mail via outlook and input parameters from excel sheet
    By ashayk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2011, 02:33 AM
  5. Replies: 3
    Last Post: 08-11-2006, 09:10 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