printing macro,want to use beforeprint event?

P

paul

below is a macro I have written/recorded.My macro skills are pretty basic(no
pun intended!)I always start with a recorded procedure and go on from there.
The idea of this prcedure is two fold.
1) print only the worksheets used
2) check that freight has been allowed on each sheet(product type)
3)I am aware that I have not "dim" at the start but i dont undersand that
stuff
In my mind this could be activated by the before print event but i notice
that the before print event is triggered evrytime the .printout call is made
How should i call it,just a button on the sheet or toolbar?
4)At the moment it just lives in a general module of the quote template but
i dont really want it in every quote i do.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 26/06/2006 by paul
'

ScreenUpdating = False
If Range("framefreight") = 0 And Range("framesell") > 0 Then
myfrfreight = InputBox("Enter Freight for frames in hrs then ok to
continue or cancel to exit.Enter 0 to enter no freight or cancel to exit to
workbook", "Freight", 2)
If myfrfreight = "" Then
Exit Sub
Else
Range("framefreight") = myfrfreight
End If
End If
If Range("trussfreight") = 0 And Range("trusssell") > 0 Then
mytrfreight = InputBox("Enter Freight for trusses in hrs then ok to
continue or cancel to exit.Enter 0 to enter no freight or cancel to exit to
workbook", "Freight", 2)
If mytrfreight = "" Then
Exit Sub
Else
Range("trussfreight") = mytrfreight
End If
End If
If Range("posifreight") = 0 And Range("posisell") > 0 Then
mypofreight = InputBox("Enter Freight for frames in hrs then ok to
continue or cancel to exit.Enter 0 to enter no freight or cancel to exit to
workbook", "Freight", 2)
If mypofreight = "" Then
Exit Sub
Else
Range("posifreight") = mypofreight
End If
End If
If Range("rafterfreight") = 0 And Range("raftersell") > 0 Then
myrafreight = InputBox("Enter Freight for frames in hrs then ok to
continue or cancel to exit.Enter 0 to enter no freight or cancel to exit to
workbook", "Freight", 2)
If myrafreight = "" Then
Exit Sub
Else
Range("rafterfreight") = myrafreight
End If
End If
Sheets("Cover").Select
Application.Dialogs(xlDialogPrint).Show
If Range("framesell") > 0 Then
Sheets("Frame").PrintOut Copies:=1
End If
If Range("trusssell") > 0 Then
Sheets("Truss").PrintOut Copies:=1
Sheets("Truss Materials").PrintOut Copies:=1
End If
If Range("posisell") > 0 Then
Sheets("posi").PrintOut Copies:=1
End If
If Range("raftersell") > 0 Then
Sheets("Rafter").PrintOut Copies:=1
End If
If Range("mismattot") > 0 Then
Sheets("mismat").PrintOut Copies:=1
End If
ScreenUpdating = True
End Sub
 
D

davesexcel

paul said:
1) print only the worksheets used
You could do something like this...

Sheets("Select").Select
If ActiveSheet.Range("F5").Value < 1 Then
Sheets("two").Select
ActiveWindow.SelectedSheets.Visible = False
End If
'Print three
Sheets("Select").Select
If ActiveSheet.Range("F6").Value < 1 Then
Sheets("three").Select
ActiveWindow.SelectedSheets.Visible = False
End If

in this example...
if Sheet"Select"range F5 is less then 1 then Hide sheet "two"
if Sheet"Select"range F6 is less then 1 then Hide sheet "three"
then in your macro you could have print entire workbook and only the
sheets that are visible will be printed
in the same macro after the print command you should make sheets
visible again

Sheets("two").Visible = True
Sheets("three").Visible = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top