Excel 2010 Before Print Event not working

Posted on 2012-09-20
Last Modified: 2013-12-03
Hi Experts,

I have some VBA code that I would like to run before the user sends the print job to the printer.  I have tried the BeforePrint event in the workbook tab VB and cannot get the code run.  I have even tried to simply the code as follows and still not working,

Private Sub Workbook_BeforePrint(Cancel As Boolean)

    MsgBox ("hi")

End Sub

Any thoughts on what could prevent this from running?

Thanks in advance

Question by:JJINFM
    LVL 85

    Expert Comment

    by:Rory Archibald
    It appears to be a bug. I've seen reports that it doesn't work 'by design' when using the backstage preview but it was supposed to work using the old full screen print preview, however I cannot get it to fire ever in my tests. I will file it as a bug.

    Author Comment

    OK, how to I resolve this open question.  Do I accept your comment as a solution?
    LVL 85

    Expert Comment

    by:Rory Archibald
    I'd suggest you leave it open for the time being and I will see if I get a response from MS that I can pass on, even if it's just confirmation of the issue.
    LVL 85

    Expert Comment

    by:Rory Archibald
    Hmm, just retested and after compiling my code I can now get the event to fire for a full screen preview or a print, but not from a Backstage preview (i.e. the File-Print screen) unless I actually print.
    LVL 85

    Accepted Solution

    I think the lack of event from the backstage preview is by design, but actually printing or doing a full screen preview should fire it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now