+ Reply to Thread
Results 1 to 8 of 8

Disable print but allow PDF printing

  1. #1
    Registered User
    Join Date
    11-16-2015
    Location
    bradford
    MS-Off Ver
    2013
    Posts
    18

    Disable print but allow PDF printing

    I'm trying to set up a spreadsheet so that it cannot be physically printed, but I have a macro button to save as a PDF which I need to work.

    I've used the following codes:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    both work indivually but together the code to disable printing also stops the PDF from being written.

    Is there a way to overcome this? I do have another tab that saves as a PDF as well that follows the same code, and as I have looked the workbook this also cannot be written to a PDF. I'm happy to only lock one worksheet, but I struggled to make this work...

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Disable print but allow PDF printing

    This works
    add a first line to Sub SaveQuoteAsPDF
    Sheets("Sheet1").Range("A10") - change this to whichever cell and sheet works for you
    Please Login or Register  to view this content.
    then amend the BeforePrint as follows (remember to reset that cell back to blank within the If...End if)
    Please Login or Register  to view this content.
    This adds as a switch.
    If the cell contains the value "Print PDF" then it allows printing
    Otherwise if cell is blank, no printing allowed
    Last edited by Kevin#; 03-03-2016 at 12:56 PM.

  3. #3
    Registered User
    Join Date
    11-16-2015
    Location
    bradford
    MS-Off Ver
    2013
    Posts
    18

    Re: Disable print but allow PDF printing

    This works great thanks.

    I have 2 other worksheets that need to follow the same rule, but the macro print button isn't in the same place, (roughly F9) and it takes the cell name from E21.

    This says it subscript out of range so how can I change the print range for these macros? I don't really understand how the range ("A10")makes it work?

  4. #4
    Registered User
    Join Date
    11-16-2015
    Location
    bradford
    MS-Off Ver
    2013
    Posts
    18

    Re: Disable print but allow PDF printing

    This works great thanks.

    I have 2 other worksheets that need to follow the same rule, but the macro print button isn't in the same place, (roughly F9) and it takes the cell name from E21.

    This says it subscript out of range so how can I change the print range for these macros? I don't really understand how the range ("A10")makes it work?

  5. #5
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Disable print but allow PDF printing

    It is nothing to do with where the print button is.
    Choose a cell, any cell, anywhere in the workbook, on any worksheet. A cell that is away from your data.
    The same cell can be used for all the worksheets.
    The cell is used to either hold the words "PRINT PDF" or to be blank.

    The new line(below) in Sub SaveQuoteAsPDF places the words "PRINT PDF" in that cell
    Please Login or Register  to view this content.
    When you run SaveQuoteAsPDF we need to stop the BeforePrint from cancelling your PDF report and we do this by putting a condition in the BeforePrint macro, telling it to look at the value of the cell that may (or may not) contain the words "PRINT PDF". The condition is in this in line:
    Please Login or Register  to view this content.
    If the condition is satisfied (ie the cell contains "PRINT PDF") then it bypasses the "cancel" print control

    The next line in the same macro re-instates the value in the cell to blank, stopping anyone from printing again
    Please Login or Register  to view this content.
    In summary when your run the PDF macro it temporarily changes the value of one cell to include the words "PRINT PDF" and it is then changed back to blank again by the BeforeClose macro.
    Hope this helps.

  6. #6
    Registered User
    Join Date
    11-16-2015
    Location
    bradford
    MS-Off Ver
    2013
    Posts
    18

    Re: Disable print but allow PDF printing

    Thanks,

    This makes a lot more sense now, though I am still having trouble getting it to work on the other 2 sheets.

    I chose A7 as that cell is empty on each sheet, and changed the code for each Print PDF macro, but how do I get it all into the cancle print macro?

    I've tried a few variations but nothing I have done seems to work. I can't have separate macros for each sheet as the name is ambiguous, and I'm not sure how to get each sheet into one macro.

    The sheets are:
    Sheet1
    Sheet14
    Sheet15

    Thanks!

  7. #7
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Disable print but allow PDF printing

    Only use one cell - NOT one in each worksheet.


    The pdf Macro for sheet1 should contain the line
    Please Login or Register  to view this content.
    The pdf Macro for sheet14 should contain EXACTLY THE SAME the line
    Please Login or Register  to view this content.
    The pdf Macro for sheet15 should contain EXACTLY THE SAME the line
    Please Login or Register  to view this content.
    and, finally, the BeforePrint macro should contain the line
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-16-2015
    Location
    bradford
    MS-Off Ver
    2013
    Posts
    18

    Re: Disable print but allow PDF printing

    Thanks SO much, this has solved it!

+ 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. Replies: 1
    Last Post: 06-11-2014, 09:23 AM
  2. Disable Print button in Full Print Preview
    By RaquelAR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-17-2013, 02:03 PM
  3. Disable printing bar one sheet
    By Ad83 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2012, 09:15 AM
  4. disable hyperlinks while printing
    By ravindar.thati in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2009, 09:47 AM
  5. Disable printing problems
    By Simon-ch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-19-2009, 11:21 AM
  6. Replies: 4
    Last Post: 02-17-2006, 08:36 AM
  7. printing multiple print areas with a print dialog box
    By LHaro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2005, 05:05 PM
  8. [SOLVED] Disable Printing
    By JOHN SMITH in forum Excel General
    Replies: 2
    Last Post: 04-13-2005, 08: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