+ Reply to Thread
Results 1 to 10 of 10

Button to copy and e-mail out worksheet with added functionality

  1. #1
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Button to copy and e-mail out worksheet with added functionality

    I have a button with some simple code that copies Sheet2 and opens it in a new workbook:
    Please Login or Register  to view this content.
    Two extra things I'd like
    1) Would it be possible to e-mail this sheet out when opened? If the functionality of "Would you like to e-mail this sheet out?" popped up as a Yes/No message box then even better. If no is selected then they can just view the sheet. If yes is selected an Outlook message window opens with the file attached?

    2) I currently get a "Subscript out of range" error when the Sheet2 opens, I think this may be because I am only copying Sheet2, but within the code of Sheet2 it looks at other sheets...for example the part in red below, it is taking to a sheet called "Archive":

    Please Login or Register  to view this content.
    Is there a way to lose all relationships between other sheets when the copy of Sheet2 is created? I only wish for it to be a 'snapshot' and am not bothered about the main code functionality from the master file coming across...

    Thanks in advance.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Button to copy and e-mail out worksheet with added functionality

    This will copy Sheet2 without code and prompt the user if they want to Email the sheet. If "Yes", it calls another procedure called EmailSheet.

    There are several options to how you want to email the sheet. The code for that can be found here...

    Mail from Excel

    Chose the method you want and put the code in the EmailSheet procedure.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Button to copy and e-mail out worksheet with added functionality

    Great, thank you for this.

    I have used the "Mail one sheet" option to mail and it seems to work great

    Just one point:

    Is there any way to keep the formatting of Sheet2 when it is copied? What you have posted loses the code which is great but loses the formatting also and I'd like to keep this if possible (apologies I should have said in my OP).

    Thanks!

  4. #4
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Button to copy and e-mail out worksheet with added functionality

    Can anyone assist with my post #3 above?

    I read that xlPasteFormats could work? So I tried
    Please Login or Register  to view this content.
    but this didn't seem to work... any ideas?

    thanks

  5. #5
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Button to copy and e-mail out worksheet with added functionality

    Is anybody able to help with the above? All I'd like to add is some code which ensures the formatting is kept when the new sheet is created

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Button to copy and e-mail out worksheet with added functionality

    Here is the foundation of what you need. You'll need to change sheet name and/or references:

    Sub CopyWorksheetValues()
    ActiveSheet.Copy
    Cells.Copy
    Range("A1").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Button to copy and e-mail out worksheet with added functionality

    Logit - thanks.

    I've amended what you posted to suit my code as follows:

    Please Login or Register  to view this content.
    It now copies over the formatting, great
    Only issue I'm facing is that it seems to bring over all of my code, code which references other sheets that aren't in this single sheet snap shot (same issue as in my OP). Is there anyway to amend the above so it doesn't look for sheets out of range? As I am receiving a subscript out of range error when the sheet opens.

    Many thanks
    Last edited by JRC1; 03-15-2017 at 11:31 AM.

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Button to copy and e-mail out worksheet with added functionality

    You want to copy Sheet2 - only the data - no formulas ... correct ?

    Where are you pasting this to ? What is the name of the sheet ?

    Is it in the same workbook or in another workbook ?

  9. #9
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Button to copy and e-mail out worksheet with added functionality

    Only wish to copy Sheet2 values, correct.
    Pasting to a new workbook which will open as just Sheet2.

  10. #10
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Button to copy and e-mail out worksheet with added functionality

    Basically, everything in the above code worked perfect, I just do not wish to reference any other sheets, such as the Archive sheet in Post #1 that is causing the error. Thanks

+ 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. Automatically add button when data added to cell and apply macro to button?
    By dori2o in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2016, 11:56 AM
  2. Simulate Mail merge functionality in excel?
    By OanaC in forum Excel General
    Replies: 0
    Last Post: 03-15-2015, 11:04 PM
  3. Browse functionality on Excel sheet (samples added)
    By aukhan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2013, 10:48 PM
  4. Forum Gurus receive an added functionality
    By arlu1201 in forum The Water Cooler
    Replies: 9
    Last Post: 10-01-2012, 05:43 PM
  5. Get index of a button added to worksheet
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-10-2007, 06:25 PM
  6. Programmatically Added Checkbox Functionality
    By TomJones322 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-26-2005, 03:59 PM
  7. [SOLVED] e-mail the current worksheet using a form button
    By Richard Smack in forum Excel General
    Replies: 2
    Last Post: 01-14-2005, 01:06 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