+ Reply to Thread
Results 1 to 9 of 9

Cancel As Boolean Help

  1. #1
    Registered User
    Join Date
    07-25-2014
    Location
    Florida, USA
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Cancel As Boolean Help

    Hello everyone, I'm looking for a bit of help on this issue I've been getting when I tried to combine 2 snippets of code together. I'm really a excel newbie and have been messing around with for quite some time, I can usually find the answer online but I'm stumped on this one.

    Code:
    Please Login or Register  to view this content.
    I get a run-time error '1004', application defined or object defined error when I try printing. What I'm using this code for is to make sure some users input something in those specified cells AND hide a few different other cells when printing (by turning the text white I guess). The 2 separate codes work just fine when I use either one separately, but when I combined (or tried to anyways) them i get an error. I know nothing about programming so I'm really stumped, I'm sure there's a IF-ELSE-THEN statement I'm not making or something like that. Any help would be greatly appreciated. Thanks again!

    Edit: [Solved]
    Last edited by Kiotofl; 07-25-2014 at 11:45 AM.

  2. #2
    Registered User
    Join Date
    02-06-2013
    Location
    Ezinge, The Netherlands
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    65

    Re: Cancel As Boolean Help

    Hi Kiotofl,

    Can you upload your (example) document as well?
    It's hard to figure out which cells are checked etc.

  3. #3
    Forum Guru
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    4,168

    Re: Cancel As Boolean Help

    hi Kiotofl, welcome to Excelforum, as a quess:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-06-2013
    Location
    Ezinge, The Netherlands
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    65

    Re: Cancel As Boolean Help

    I don't get the need of hiding text when printing, what is the purpose of that? What are you trying to achieve here?
    Prevent a user to print something, before some cells are filled?

  5. #5
    Registered User
    Join Date
    07-25-2014
    Location
    Florida, USA
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Cancel As Boolean Help

    It would be probably best not to upload the form just because it has internal company information, and the reason I 'm trying to hide some cells is because the customers receiving the printed version (PDF or otherwise) should not have some of this "internal information" shown to them such as internal cost, warranty and contact information. This is useful for the person creating this estimate, but it should not be seen by the customer receiving the printed version of the form. Does this make sense?

  6. #6
    Registered User
    Join Date
    07-25-2014
    Location
    Florida, USA
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Cancel As Boolean Help

    I'm so dumb. My code works just fine but I locked the cells and protected the sheet (to keep the users from making changes to these fields) and that was the problem the whole time. So now that I unlocked those cells and unprotected the sheet, the code works for both functions, to hide some cells and to prevent the user from printing without filling the required cells. So that solved that problem, but a new problem arises, is there a way this could work WITH the locked cells and protected sheet? Also, is there a way that I could hide the condition as well? I noticed that if I have a condition for one of the cells I'm trying to hide (for instance, turn the text color red if a warranty is expired) if the condition is met, the text will not hide.
    Last edited by Kiotofl; 07-25-2014 at 09:39 AM.

  7. #7
    Registered User
    Join Date
    02-06-2013
    Location
    Ezinge, The Netherlands
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    65

    Re: Cancel As Boolean Help

    Hahah, well... that happens with all of at some end I think :-)
    Yes you can, you can Unprotect your sheet before printing and Protect it again after print. But thats another topic!

  8. #8
    Registered User
    Join Date
    07-25-2014
    Location
    Florida, USA
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Cancel As Boolean Help

    Well I found a solution again for this. I ended up having to run a Sheets("SheetName").Unprotect & Sheets("SheetName").Protect before and after the initiation of the VBA code. I guess VBA doesn't like locked/merged cells win conjunction with having a protected sheet. This fixed all of the issues I was having and here's how the code looks now:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-06-2013
    Location
    Ezinge, The Netherlands
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    65

    Re: Cancel As Boolean Help

    Yes, that should be alright I think

+ 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. [SOLVED] Private Sub Workbook_BeforePrint(Cancel As Boolean) Range Issue (2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-16-2014, 10:31 AM
  2. Workbook_BeforeClose(cancel As Boolean)
    By Vdogeek in forum Excel General
    Replies: 3
    Last Post: 05-23-2014, 12:39 PM
  3. Private Sub Workbook_BeforePrint(Cancel As Boolean) not executing procedures
    By Burrswood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2013, 11:48 AM
  4. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) problem
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2009, 07:28 PM
  5. [SOLVED] Cancel Macro is user selects 'cancel' at save menu
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2005, 01: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