+ Reply to Thread
Results 1 to 5 of 5

BeforePrint macro

  1. #1
    Steve O
    Guest

    BeforePrint macro

    Hello,

    I'm looking for code to check a value in a cell and if that value is 0 then
    continue to print. If the value is any number other than 0 then display a
    message box stating that the sheet does not balance and let the user go back
    to the sheet and fix. Here is the code I have so far with no success

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If Range("A42") <> 0 Then PrintOut = False
    End Sub


    Thanks for any input.
    Steve



  2. #2
    Dave Peterson
    Guest

    Re: BeforePrint macro

    How about:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If worksheets("sheet99").Range("A42") <> 0 Then
    cancel = true
    end if
    End Sub

    Maybe adding a msgbox would help the user understand why his/her listings never
    show up!


    Steve O wrote:
    >
    > Hello,
    >
    > I'm looking for code to check a value in a cell and if that value is 0 then
    > continue to print. If the value is any number other than 0 then display a
    > message box stating that the sheet does not balance and let the user go back
    > to the sheet and fix. Here is the code I have so far with no success
    >
    > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > If Range("A42") <> 0 Then PrintOut = False
    > End Sub
    >
    > Thanks for any input.
    > Steve


    --

    Dave Peterson

  3. #3
    Steve O
    Guest

    Re: BeforePrint macro

    Thanks Dave..

    In regardsto the message box do I need to add it after the cancel = true as
    an if statement also. I not able to get the message box to appear when the
    true condition exists.

    "Dave Peterson" wrote:

    > How about:
    >
    > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > If worksheets("sheet99").Range("A42") <> 0 Then
    > cancel = true
    > end if
    > End Sub
    >
    > Maybe adding a msgbox would help the user understand why his/her listings never
    > show up!
    >
    >
    > Steve O wrote:
    > >
    > > Hello,
    > >
    > > I'm looking for code to check a value in a cell and if that value is 0 then
    > > continue to print. If the value is any number other than 0 then display a
    > > message box stating that the sheet does not balance and let the user go back
    > > to the sheet and fix. Here is the code I have so far with no success
    > >
    > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > > If Range("A42") <> 0 Then PrintOut = False
    > > End Sub
    > >
    > > Thanks for any input.
    > > Steve

    >
    > --
    >
    > Dave Peterson
    >


  4. #4
    Dave Peterson
    Guest

    Re: BeforePrint macro

    You could put the msgbox line anywhere between the If/End if pair:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If worksheets("sheet99").Range("A42") <> 0 Then
    Msgbox "Please balance your workbook--look at sheet99 cell A42"
    cancel = true
    Msgbox "or you could put it here, but don't use both"
    end if
    End Sub

    ps. I should have read your original message better. I see that you said you
    wanted a msgbox added!



    Steve O wrote:
    >
    > Thanks Dave..
    >
    > In regardsto the message box do I need to add it after the cancel = true as
    > an if statement also. I not able to get the message box to appear when the
    > true condition exists.
    >
    > "Dave Peterson" wrote:
    >
    > > How about:
    > >
    > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > > If worksheets("sheet99").Range("A42") <> 0 Then
    > > cancel = true
    > > end if
    > > End Sub
    > >
    > > Maybe adding a msgbox would help the user understand why his/her listings never
    > > show up!
    > >
    > >
    > > Steve O wrote:
    > > >
    > > > Hello,
    > > >
    > > > I'm looking for code to check a value in a cell and if that value is 0 then
    > > > continue to print. If the value is any number other than 0 then display a
    > > > message box stating that the sheet does not balance and let the user go back
    > > > to the sheet and fix. Here is the code I have so far with no success
    > > >
    > > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > > > If Range("A42") <> 0 Then PrintOut = False
    > > > End Sub
    > > >
    > > > Thanks for any input.
    > > > Steve

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  5. #5
    Steve O
    Guest

    Re: BeforePrint macro

    No trouble at all...thank you for the response it works great! I really
    appreciate your help!

    "Dave Peterson" wrote:

    > You could put the msgbox line anywhere between the If/End if pair:
    >
    > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > If worksheets("sheet99").Range("A42") <> 0 Then
    > Msgbox "Please balance your workbook--look at sheet99 cell A42"
    > cancel = true
    > Msgbox "or you could put it here, but don't use both"
    > end if
    > End Sub
    >
    > ps. I should have read your original message better. I see that you said you
    > wanted a msgbox added!
    >
    >
    >
    > Steve O wrote:
    > >
    > > Thanks Dave..
    > >
    > > In regardsto the message box do I need to add it after the cancel = true as
    > > an if statement also. I not able to get the message box to appear when the
    > > true condition exists.
    > >
    > > "Dave Peterson" wrote:
    > >
    > > > How about:
    > > >
    > > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > > > If worksheets("sheet99").Range("A42") <> 0 Then
    > > > cancel = true
    > > > end if
    > > > End Sub
    > > >
    > > > Maybe adding a msgbox would help the user understand why his/her listings never
    > > > show up!
    > > >
    > > >
    > > > Steve O wrote:
    > > > >
    > > > > Hello,
    > > > >
    > > > > I'm looking for code to check a value in a cell and if that value is 0 then
    > > > > continue to print. If the value is any number other than 0 then display a
    > > > > message box stating that the sheet does not balance and let the user go back
    > > > > to the sheet and fix. Here is the code I have so far with no success
    > > > >
    > > > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    > > > > If Range("A42") <> 0 Then PrintOut = False
    > > > > End Sub
    > > > >
    > > > > Thanks for any input.
    > > > > Steve
    > > >
    > > > --
    > > >
    > > > Dave Peterson
    > > >

    >
    > --
    >
    > Dave Peterson
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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