+ Reply to Thread
Results 1 to 22 of 22

Protect each worksheet before emailing out

  1. #1
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Protect each worksheet before emailing out

    Hi All,

    I am looking for some help here. I have a worksheet of 30 tabs for each driver to show their weeks work, I want to email each driver every week their respective sheet.
    I found some code online as follows which works very well and emails the individual sheets to each driver, but I really want to protect each work sheet that the driver receives so they cannot be changed, how would I do this. The range on each sheet would be A1:K42.

    Thanks

    Please Login or Register  to view this content.
    ==========
    Bigroo1958
    Austin, Texas
    ==========

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    Rather than save the sheet to a new workbook and then as a temporary .xlsx file, save it as a .pdf file. Then all they can do is look at it, no changes possible. Also more portable.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    TMS,

    Thanks for the reply, this is a pretty great idea, what do I need to change in my code above to make this work and save as a PDF file?
    Do you have code example that I could use?
    Thanks

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    On holiday at the moment with no computer in sight

    But just record a macro while you save the active sheet as a .pdf file. Then change the file name structure in the same way you have for the .xlsx file

  5. #5
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    TMS,

    Thanks for the reply, I have had sometime today to look at this further. After recording a macro and saving as a .pdf file, this is what the code is, but unsure where to place this code.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    Ok, that code creates a .pdf file with the temporary file name (so you can still delete it later). And that works for the sheet you are processing.

    You don't, therefore, need to copy the sheet to a new workbook, save the newly created active workbook, or even define a workbook object so you can keep track of it.

    So replace the workbook creating and saving code with your .pdf exporting code.

  7. #7
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    Thanks TMS,

    I don't understand what you mean sorry, I placed that code where it talks about .xlsx but I get and 'Object required" runtime error 424.

    Please Login or Register  to view this content.
    What object is this looking for or should I place this somewhere else?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    Untested, but fill in the .pdf bit and try this:

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    Thank TMS,

    I am stuck, here is what I have but getting runtime error 91..., what am I doing wrong?

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    TMS,

    I have modified my export part of the PDF with this,, I now receive the email but no attachment and I get an error saying file not found at the Kill TempFilePath & TempFileName & FileExtStr line.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    As I said, I can't test anything. Why did you add wb.TempFilePath? That wasn't in the code you recorded.

    Perhaps this will help: http://www.contextures.com/excelvbapdf.html

  12. #12
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    I added wb.TempFilePath because nothing else would work, I kept getting errors.
    I will review the link you sent.

    Thanks!

  13. #13
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    Thanks TMS,

    Ok, I have made progress today, I am now receiving the email with the PDF file attached, but I am now receiving an error message when I try to open the PDF file, see attachment.

    Also, here is the vba code:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    Looks to me as though you are still saving and attaching a workbook object, the difference being that you are making the extension .pdf. Hence why Acrobat can't open it.

  15. #15
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    As I have pointed out in a few posts back, I was getting file not found, so I went back to the original code.
    Since TMS is on holiday and no access to a computer, can someone else please offer some assistance so I can finish off my project?

    Thanks

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    Three basic things to do:

    1. Build a full file path for the saved file including the temp directory location, the file name based on the sheet name and date, and the extension, which needs to be .pdf
    2. Export the current/active sheet using the file/path name from step 1
    3. Create your email and attach the file using the file/path name from step 1

    Then 4. Delete the temporary file exported in step 2 using the file/path name from step 1.

    You have code or examples for each step, so it's just a case of linking them together.

    Because you are exporting a .pdf file, you can get rid of the checks for the Excel version. You don't need to copy the sheet to a new workbook and save it. Forget all that. Just focus on the three steps listed above.

    You don't need to Dim and Set/Create a wb object. You are replacing that by exporting the sheet as a .pdf file.

    Not sure how I can say it differently

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    In case the instructions above don't help, I've asked for others to take a look.

  18. #18
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Protect each worksheet before emailing out

    Ron has a whole section on emailing out PDF files which can be found here

    http://www.rondebruin.nl/win/s5/pdf.htm

    the one that matches most with what you want is
    Mail_Every_Worksheet_With_Address_In_A1_PDF

    Replace A1 with A37
    Please Login or Register  to view this content.
    and the tempfilename
    Please Login or Register  to view this content.
    it should work
    Last edited by humdingaling; 04-28-2016 at 11:31 PM. Reason: changed tempfilename
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  19. #19
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Protect each worksheet before emailing out

    see attached file created based on Ron's code
    can't post full code due to HTML in it
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    Thanks TMS!

    I appreciate your patience and assistance with me, I am still learning this language, some I am beginning to understand, the correct syntax is what is rough for me, I have a long way to go.
    Your explanation is very clear and step by step.

    Thanks

  21. #21
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: Protect each worksheet before emailing out

    G'Day Humdingaling,

    Thanks for your code example, this worked nicely and has giving me the results I am looking for and has helped me get my original code working along with TMS's detailed explanation.

    Thanks again, bonza mate!!!!

  22. #22
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Protect each worksheet before emailing out

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Emailing a Worksheet
    By BazzaBoy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2010, 04:18 AM
  2. Protect Worksheet before Emailing
    By jman0707 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-06-2009, 09:28 AM
  3. emailing worksheet.
    By rymcc83 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2009, 11:41 PM
  4. Emailing A Worksheet
    By viruzman in forum Excel General
    Replies: 1
    Last Post: 03-22-2008, 01:13 PM
  5. emailing a worksheet
    By fry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2007, 08:38 AM
  6. Replies: 6
    Last Post: 12-27-2005, 04:20 AM
  7. Replies: 5
    Last Post: 08-09-2005, 11:05 AM
  8. Emailing a worksheet
    By Craig in forum Excel General
    Replies: 0
    Last Post: 05-13-2005, 04:06 PM

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