PDA

View Full Version : auto print



niyrho
07-24-2008, 01:24 PM
I got this code on here:


Private Sub Workbook_BeforePrint(Cancel As Boolean)
On Error Goto Exits
Cancel = True
Application.EnableEvents = False
With ActiveSheet
ActiveWorkbook.SaveCopyAs "C:\Work Orders\" & .Range("A1") & Format(.Range("A2"), " yy-mm-dd") & ".xls"
.PrintOut
.Range("A1:A2").ClearContents
End With
Exits:
Application.EnableEvents = True
End Sub


I got two problems. This code isn't working at all now, I think I might be entering it wrong. And I need it to only print up to the first page that isn't filled out.

mdmackillop
07-24-2008, 01:51 PM
Your code looks fine.
Run this to make sure Events are enabled

Sub Enables()
Application.EnableEvents = True
End Sub



And I need it to only print up to the first page that isn't filled out.

You need to be more specific.

niyrho
07-25-2008, 02:21 AM
Code still isn't working at all. It just acts like I don't have any macros. And I'm still missing one of the functions I need.

mdmackillop
07-25-2008, 03:11 AM
Start from scratch
Is there something to print?
Does ActiveSheet.Printout work?
Does this show the message box?

Private Sub Workbook_BeforePrint(Cancel As Boolean)
msgbox "Printing"
End Sub


and so on.

f2e4
07-25-2008, 03:24 AM
Can you post a sample worksheet with the current code you are using?

mdmackillop
07-25-2008, 03:28 AM
If there is an error created by this line, nothing will print. Try commenting it out.

ActiveWorkbook.SaveCopyAs "C:\Work Orders\" & .Range("A1") & Format(.Range("A2"), " yy-mm-dd") & ".xls"