+ Reply to Thread
Results 1 to 14 of 14

Thread: Print Macro

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Print Macro

    I've added a "print" button with a simple recorded macro into a spreadsheet. When the user hits the print button, I need something that looks at cell P14 and shows an error message if the value = 1, also it needs to look at P15 and show a different error message if that value = 1. If either are one, the print macro should halt until both values return to 0. HELP! Thanks!!!
    Last edited by pduback; 06-28-2011 at 04:25 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Print Macro

    Hello pduback,

    Welcome to the Forum!

    It would help to see the recorded macro code. What do you want each error message to say?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    Thanks - glad I found this place! I actually deleted the macro for some random reason. Sounds like it would be helpful if I re-recorded it and posted? The message would be custom...something like "Fee schedules must be entered in descending order, please adjust..." I've written a formula into P14 to = 1 if the condition isn't met, 0 if it has been met. I'll re-record the macro and post it. Thanks for your help!

  4. #4
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    Here's the macro that I recorded to print. Any help would be HUGELY appreciated!

  5. #5
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    Sorry, forgot to paste it in:
    Sub Print_Macro()
    '
    ' Print_Macro Macro
    '
    
    '
        Sheets("Fee Calculator").Select
        Sheets("Printed Schedule").Visible = True
        Sheets("Fee Calculator").Select
        ActiveWindow.SelectedSheets.Visible = False
        Sheets("Printed Schedule").Select
        ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
        Sheets("Printed Schedule").Select
        Sheets("Fee Calculator").Visible = True
        Sheets("Printed Schedule").Select
        ActiveWindow.SelectedSheets.Visible = False
    End Sub
    Last edited by Leith Ross; 06-28-2011 at 01:35 PM. Reason: Added Code Tags

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Print Macro

    Hello pduback,

    Try this version of the macro. Change the message for P15. It is marked in bold.
    Sub Print_Macro()
    '
    ' Print_Macro Macro
    '
    
    '
        Sheets("Fee Calculator").Select
        Sheets("Printed Schedule").Visible = True
        Sheets("Fee Calculator").Select
        ActiveWindow.SelectedSheets.Visible = False
        Sheets("Printed Schedule").Select
        If Range("P14") = 1 Then 
           MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly
           Exit Sub
        End If
        If Range("P15") = 1 Then 
           MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly
           Exit Sub
        End If
        ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
        Sheets("Printed Schedule").Select
        Sheets("Fee Calculator").Visible = True
        Sheets("Printed Schedule").Select
        ActiveWindow.SelectedSheets.Visible = False
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    No luck with the additional code. If P14 or P15 (or both) are 1s, the print still goes off and no message box appears. Would love other ideas if you have them? Thanks again.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Print Macro

    Hello pdubuck,

    Could be we are not checking the correct sheet. The macro is using P14 and P15 on the "Printed Schedule". Is that the correct sheet?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  9. #9
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    Nope. P14/15 are on "Fee Calculator"

    Don't want to monkey with it until you tell me what to do...

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Print Macro

    Hello pduback,

    Okay, this should work.
    Sub Print_Macro()
    '
    ' Print_Macro Macro
    '
    
    '
        Sheets("Fee Calculator").Select
        Sheets("Printed Schedule").Visible = True
        Sheets("Fee Calculator").Select
        If Range("P14") = 1 Then 
           MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly
           Exit Sub
        End If
        If Range("P15") = 1 Then 
           MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly
           Exit Sub
        End If
        ActiveWindow.SelectedSheets.Visible = False
        Sheets("Printed Schedule").Select
        ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
        Sheets("Printed Schedule").Select
        Sheets("Fee Calculator").Visible = True
        Sheets("Printed Schedule").Select
        ActiveWindow.SelectedSheets.Visible = False
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  11. #11
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    Great - that solved that. One thing....if the error message is triggered, the macro stops, but the "Printed Schedule" page is left unhidden....can you add code to it to make it so if the error message is displayed, Printed Schedule remains hidden? Not sure if my questions are out of bounds for the forum - i'll trust you to tell me if so - but I really appreciate the help. Pete

  12. #12
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    Is that just a matter of switching the order in the code?

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Print Macro

    Hello pduback,

    In this case, yes. The Range property applies to the ActiveSheet unless it has been qualified with a worksheet name like below.
        Worksheets("Sheet1").Range("A1")

    Since "Fee Calculator" is made active before the IF...THEN statements, the Range is assumed to be on the active sheet which is "Fee Calculator".
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  14. #14
    Registered User
    Join Date
    06-28-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Print Macro

    I switched a few lines and it is working perfectly. THANKS!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0