PC Review


Reply
Thread Tools Rate Thread

Automatically run Macro before printing

 
 
BLW
Guest
Posts: n/a
 
      24th May 2008
I have written this macro to set page breaks once all info is added to the
spreadsheet. Is there anyway to have the Macro run automatically when the
user prints or previews? Or is it better is attach it to a button for them
to click before printing?

Thanks for any help - BLW

Sub PageBreak()

Range("A1").Select
Do While ActiveCell.Value <> "End"
ActiveCell.Offset(20, 0).Select
value1 = ActiveCell.Value
If value1 = "ReMax" Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
Else
Do While ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
value1 = ActiveCell.Value
If value1 = "ReMax" Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
Loop
End If
Loop
End Sub
 
Reply With Quote
 
 
 
 
Gord Dibben
Guest
Posts: n/a
 
      24th May 2008
Private Sub Workbook_BeforePrint(Cancel As Boolean)

your code or macroname here

End Sub

Which is better? That would be your preference but clicking a button to
activate a macro then clicking on the Print Icon is not as easy as clicking on
the Print Icon to achieve the same thing.


Gord Dibben MS Excel MVP

On Sat, 24 May 2008 14:38:00 -0700, BLW <(E-Mail Removed)> wrote:

>I have written this macro to set page breaks once all info is added to the
>spreadsheet. Is there anyway to have the Macro run automatically when the
>user prints or previews? Or is it better is attach it to a button for them
>to click before printing?
>
>Thanks for any help - BLW
>
>Sub PageBreak()
>
> Range("A1").Select
> Do While ActiveCell.Value <> "End"
> ActiveCell.Offset(20, 0).Select
> value1 = ActiveCell.Value
> If value1 = "ReMax" Then
> ActiveCell.EntireRow.Select
> ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
> Else
> Do While ActiveCell.Value = ""
> ActiveCell.Offset(1, 0).Select
> value1 = ActiveCell.Value
> If value1 = "ReMax" Then
> ActiveCell.EntireRow.Select
> ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
> End If
> Loop
> End If
> Loop
>End Sub


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      25th May 2008
Look in the ThisWorkbook module for the "before print" event. You probably
want to restrict to a single sheet.
Also, your macro could stand some pruning. Exactly what are you trying to
do? Something like this maybe that sets a pagebreak before each instance of
remax

Sub setpagebreaks()
With Worksheets(1).Range("a1:a500")
Set c = .Find("ReMax", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
' MsgBox c.Row
ActiveSheet.HPageBreaks.Add Before:=c
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"BLW" <(E-Mail Removed)> wrote in message
news:56CAB910-17B1-4973-BE75-(E-Mail Removed)...
>I have written this macro to set page breaks once all info is added to the
> spreadsheet. Is there anyway to have the Macro run automatically when the
> user prints or previews? Or is it better is attach it to a button for
> them
> to click before printing?
>
> Thanks for any help - BLW
>
> Sub PageBreak()
>
> Range("A1").Select
> Do While ActiveCell.Value <> "End"
> ActiveCell.Offset(20, 0).Select
> value1 = ActiveCell.Value
> If value1 = "ReMax" Then
> ActiveCell.EntireRow.Select
> ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
> Else
> Do While ActiveCell.Value = ""
> ActiveCell.Offset(1, 0).Select
> value1 = ActiveCell.Value
> If value1 = "ReMax" Then
> ActiveCell.EntireRow.Select
> ActiveWindow.SelectedSheets.HPageBreaks.Add
> Before:=ActiveCell
> End If
> Loop
> End If
> Loop
> End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Double-sided printing and printing entire workbook in one go. Macro to help ... ?? Jim Cone Microsoft Excel Programming 2 30th Mar 2011 04:46 AM
automatically executing Excel macro after OutputTo macro I.M. Shatner Microsoft Access Macros 0 6th Aug 2009 05:18 PM
Sent Faxes are Automatically Printing on Network Printing =?Utf-8?B?RkxCaWxsMDQyMA==?= Windows XP Print / Fax 3 6th Aug 2007 06:27 PM
Automatically printing file name, date and time of printing =?Utf-8?B?RXJpa2E=?= Microsoft Powerpoint 1 22nd Mar 2005 10:51 AM
macro to automatically check spelling before printing and before saving dgb Microsoft Excel Programming 0 24th Sep 2003 12:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:25 PM.