Question

VBA -> Printing trouble .. or rather page setup

Asked by: calacuccia

Hi,

In a large application I am finalizing, I have trouble to get my page setup right.

The report, which is an Excel worksheet based on a template, is created on the fly at the end of my code.

When the report is finalized, I need to specify which pages need to be inside the 'Print Area', but I also want to adjust the Page Breaks.

Manual or forced page breaks are already partially preset in the template, but on some pages, the tables vary in length. I don't want a table to be split up in the middle of it, so I have used a method which finds me the start of the table and sets the page break by force on my preferred place.

The only problem is, that I have to rely on the automatic page breaks which Excel should fix after the report sheet is created and there lies my problem.

If I run the 'Manual Page Break' part of the macro, after the code has finalized, it works fine.

But, when inside the loop, it seems that Excel does not have the speed to calculate the page breaks, as they simply don't appear fast enough, which makes my code fail.

The question is, if anyone out here has experienced this type of behaviour, and obviously, if that particular person found a remedy for it.

I have tried to play with

Application.ScreenUpdating = False (or True)
Application.Calculation = xlCalculationManual 'or xlCalculationAutomatic

in all sort of ways, and by doing

Application.Calculate

prior to the page break part of the macro at no avail.

As an example, the line below is used to determine the total numbers of page to be printed, but does not work, for the same reason as explained above

qteSheet.PageSetup.RightFooter = "&P" & "/" & CStr(qteSheet.HPageBreaks.Count + 1)

May your thought be inspired ...

calacuccia

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2001-10-02 at 10:03:35ID20189587
Tags

page

,

excel

,

vba

,

break

Topic

Microsoft Office Suite

Participating Experts
5
Points
200
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Calacuccia
    Hi Calacuccia Here are the points I promised, nearly for free :) I have a userform that creates charts for the user at run time, all works fine except that Excel won't let me chart a 3D range eg Sheet1B6:Sheet2IV6 and I really need to be able to do this, do you know if it is...
  2. Using VBA to consolidate a Excel worksheet
    I have a worksheet with a few hundred data groups and I like to consolidate the data to another worksheet. Each data group starts with a title row looks like: *TITLE (DATA GROUP NUMBER ONE) Each group has 10-20 data lines. Each line represents a material layer and has 4 ...
  3. Points for Calacuccia
    Hi Calacuccia, My gratitude for helping the question "Hide worksheets and charts when exit". I like the idea of hiding all the worksheets except the one user request. That's neat. Thanks again. lisaswu

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: criPosted on 2001-10-03 at 01:31:38ID: 6522465

Off the cuff, how about putting a short delay, be this a 1-2 sec timer or some input box asking for some confirmation ?

 

by: forsbomPosted on 2001-10-03 at 03:52:28ID: 6522825

Hi cri
Just a shot in the dark........ Have you tried a DoEvent in the loop after each time the page break is set ???
Peter

 

by: calacucciaPosted on 2001-10-19 at 02:40:51ID: 6546223

Excuse me for slow respons, Peter and cri, EE has been down a lot lately, and my app has been taking most of my time at work. I have not had the time yet to test your suggestions though, I will try today (I hope).

calacuccia

 

by: ampPosted on 2002-01-05 at 08:28:33ID: 6712316

Geeze. I wonder if *I* have any open Qs like this. LOL

Could we get some feedback here?

We're cleaning up this topic area and need all the help we can get.

Thanks
amp
Community Support Moderator

:)
;)
:0

 

by: calacucciaPosted on 2002-01-05 at 08:33:12ID: 6712323

I still have not been able to see at the effects of the suggestions made here.
I feel so guilty :-)

 

by: ampPosted on 2002-01-05 at 08:37:01ID: 6712332

No problem, Cal. I will not let you forget. ROFLMAO.

 

by: ampPosted on 2002-01-19 at 18:57:18ID: 6743938

Reminder (you should put me in your system tray).

thanks!
amp
community support moderator

 

by: ampPosted on 2002-01-25 at 18:09:45ID: 6757310

Hello everyone.

If no response to the comments below, I will delete this question and return the points to calacuccia.

We are cleaning up this topic area. This question is considered to be *outdated* and we would like you to move on with it.

Toward that end, we graciously request the following:

-----Askers-----

*Do NOT award points to moderators (me).
*Stay active in your question. Please respond to all experts' comments immediately.
*Do one of the following, please:

  --Award points to an expert for good answer or good effort.
  --Post that you'd like to withdraw the question (the DELETE button does NOT work).
  --Ask experts for more help.

Thanks very much for being fair to our experts.

-----Experts-----

*Do NOT provide further support to this question unless asked by the Asker.
*Post your opinion on who should receive points, even if it is you, or the question may be unnecessarily deleted.
*Don't thank the moderator for granting points to you, this only causes more email for everyone (but thanks for the thought!).

Finally, if anyone does not like the moderator's determination, say so immediately and suggest your own.

Your input is extremely valuable and very much appreciated.

thank you!
amp
community support moderator
amp@experts-exchange.com

 

by: calacucciaPosted on 2002-03-18 at 04:50:47ID: 6876570

amp, the vamp,

As this topic is completely moved off my priority list, and both suggestions here are valid approaches, for the least,

I propose a points split, 100/100 pts to forsborn and cri each.

If you halve the points here, I will do the rest.

Thanks
cal

 

by: TigerManPosted on 2002-05-11 at 06:34:05ID: 7003139

calacuccia,

Just on the off-chance that this is useful, this is an answer to a messy print area question that I had some time back.

Dave

 

by: calacucciaPosted on 2002-05-17 at 03:21:11ID: 7015869

DAve,

Good to see you, what answer do you mean?

calacuccia

 

by: TigerManPosted on 2002-05-17 at 14:22:09ID: 7017432

Hi cal,

You can either see the whole discussion: http://www.experts-exchange.com/jsp/qShow.jsp?ta=msoffice&qid=10308035

or, the bulk of the code was:


The following code will insert a subtotal at the bottom of each page, a blank row and a carried forward
subtotal on each subsequent page, and a grand total two cells below the final value in column B.  After
completing the print, it will also delete the inserted rows.  This code will run if your data is set
out as you previously provided i.e. Column A contains customer details, Column B contains Numeric data
for totalling.

If yoru sheet name is not Sheet1, then you will need to change those references in the code below.

It runs at around 3-4 seconds a page on my 400.  There are no doubt quicker ways to do this, however
this method is functional.

Sorry took a while to get back to you - have a lot on at present, and probably bit off more than I should
have.


Sub PrintSubTotals()

' Init looping variable
Counter = 1

Application.ScreenUpdating = False

' Refresh page breaks and clear print areas
ActiveSheet.ResetAllPageBreaks
ActiveSheet.PageSetup.PrintArea = ""

' Loop for processing
While Worksheets("Sheet1").Cells(CStr(Counter + 1), 2).Value > 0


  ' Test if the current row + 1 has page break marker and next row in
  ' column B is not empty
  If Worksheets("Sheet1").Rows(Counter + 2).PageBreak <> xlNone And _
        Range("B" & Counter + 1).Value > 0 Then
     ' Select rows 1 either before and two after break, and insert three new rows
     Rows((Counter + 1) & ":" & (Counter + 3)).Select
     Selection.Insert Shift:=xlDown
   
     ' Show "Sub Total" in bottom of column A
     Cells(Counter + 1, 1).Select
     Cells(Counter + 1, 1).Value = "Sub Total"
     Selection.Font.Bold = True
   
     ' Set value to Sum This Page in column B
     Cells(Counter + 1, 2).Select
     ActiveCell.FormulaR1C1 = "=Sum(R[" & CStr(-Counter) & "]C2:R[-1]C2)"
   
     ' Format the SubTotal and CF cells
     Range("B" & Counter + 1).Select
     Selection.Font.Bold = True
        With Selection.Borders(xlEdgeTop)
           .LineStyle = xlContinuous
           .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
           .LineStyle = xlContinuous
           .Weight = xlThin
        End With
     
     Range("B" & Counter + 3).Select
     Selection.Font.Bold = True
     With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
     End With
     With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
     End With
   
     ' Show "Carried Forward" in Column A
     Cells(Counter + 3, 1).Select
     Cells(Counter + 3, 1).Value = "Carry Fwd."
     Selection.Font.Bold = True
   
     ' Set carry forward formula
     Cells(Counter + 3, 2).Select
     ActiveCell.FormulaR1C1 = "=(R[-2]C)"
   
     ' Refresh Page Breaks
     ActiveSheet.ResetAllPageBreaks
     ActiveSheet.PageSetup.PrintArea = ""
   
     ' Increment counter to skip the inserted blank row
     Counter = Counter + 1
   
     ' Keep track of position of last subtotal for Grand Total
     LastSub = Counter
   
  End If
 
  ' Inc counter for next in loop
  Counter = Counter + 1
Wend

' Select next empty cell in B, and insert Grand Total amount
Range("B" & Counter + 2).Select
ActiveCell.FormulaR1C1 = "=Sum(R[" & CStr(-(Counter - LastSub)) & _
                                                  "]C2:R[-1]C2)"
                                                 
' Format Grand Total cell
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
   With Selection.Borders(xlEdgeLeft)
       .LineStyle = xlContinuous
       .Weight = xlMedium
       .ColorIndex = xlAutomatic
   End With
   With Selection.Borders(xlEdgeTop)
       .LineStyle = xlContinuous
       .Weight = xlMedium
       .ColorIndex = xlAutomatic
   End With
   With Selection.Borders(xlEdgeBottom)
       .LineStyle = xlContinuous
       .Weight = xlMedium
       .ColorIndex = xlAutomatic
   End With
   With Selection.Borders(xlEdgeRight)
       .LineStyle = xlContinuous
       .Weight = xlMedium
       .ColorIndex = xlAutomatic
   End With
 
' Provide text and format
Cells(Counter + 2, 1).Value = "Grand Total"
Range("A" & (Counter + 2) & ":B" & Counter + 2).Select
Selection.Font.Bold = True

'ActiveWindow.SelectedSheets.PrintOut Copies:=1



' Processing loop to remove inserted rows
For DeleteCounter = 1 To Counter

  If Range("A" & (DeleteCounter + 1)).Value = "Sub Total" Or _
     Range("A" & (DeleteCounter + 1)).Value = "Grand Total" Then
        Rows(DeleteCounter + 1 & ":" & DeleteCounter + 3).Select
        Selection.Delete Shift:=xlUp
  End If

Next

Application.ScreenUpdating = True

End Sub



There may be something of use - particularly if you can avoid relying on XL auto break points.


Also, while you are round, did you see this one:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=msoffice&qid=20299458


Dave

 

by: bruintjePosted on 2002-08-12 at 11:01:52ID: 7214930

what to do with this one? a triple split?

 

by: bruintjePosted on 2002-08-16 at 11:31:52ID: 7225346

Hello calacuccia

time to clean up
if not stated otherwise

my recom will be
-PAQ
-points split ,cri,forsbom,TigerMan
-this will be finalized with no further update (23.08.2002)

PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER

HAGD:O)Bruintje

 

by: criPosted on 2002-08-16 at 12:41:26ID: 7225459

bruintje, thanks, but I hardly qualify for the split, it was a just a quick and dirty suggestion w/o any test.

 

by: calacucciaPosted on 2002-08-22 at 01:42:02ID: 7235455

Stating otherwise (I was back just in time :-)

All points go to Dave, although I did not test the method due to other priorities at work, it seems a good effort, which I will look at later, and I also give Dave all the points for the rude absence of any reaction from me.

calacuccia

 

by: bruintjePosted on 2002-08-22 at 13:56:07ID: 7237095

he he about time i know you would've liked to have the oldest open Q in this TA ;)

 

by: TigerManPosted on 2002-08-29 at 22:08:04ID: 7250602

Points from cal to dave?  What's the world coming to ....

Thx

NB: was of any use?

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...