View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_3_] Dick Kusleika[_3_] is offline
external usenet poster
 
Posts: 599
Default Printing Slow Down On VB Repetitive Use

R

The first thing you need to do is make your code as efficient as possible.
I would think that inefficient code would be slow all the time, not just
after the first time, but by streamlining your code, you can remove that as
a possible problem.

Here are some comments:

Dim all your integer variables as Long. Internally, VBA only uses Longs so
it's converting them for you.

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False


You set the MaxChange, then set it to the exact same value at the end. It
would seem that you don't need either of these lines, but for sure you
don't need one of them. Setting PrecisionAsDisplayed to False doesn't do
much for you. If it was set to True, the precision is lost forever, so
setting it to False changes nothing. You may want it to be False, but this
macro probably isn't the place to do it.

'
RptKey = InputBox( _
Prompt:="Choose Sale Rpt Base Type; 1-Net Whse Sales, 2-Net Total

Sales, 3-Period Variance Rpt, 4-Quarter Variance Rpt", _
Title:="Report Sales Base Type", _
Default:=1)
NumCopies = 1


This line is unnecessary. NumCopies will either be changed via the InputBox
or the If block that follows it.

NumCopies = InputBox( _
Prompt:="How Many Copies Do You Need Printed? (Maximum of 5)", _
Title:="NUMBER OF REPORTS TO PRINT", _
Default:=1)


You might consider using Application.InputBox instead of just InputBox. You
can specifiy a Type argument that will force the users to enter a number.
The way you have it now, the result is always a string. VBA is doing some
conversions for you, whcih is fine, but it slows things down.

If NumCopies 5 Then
MsgBox ("The number of copies to print is excessive, 1 will be printed.

Use the copier for multiples.")
NumCopies = 1
End If
If RptKey < "1" Or RptKey "4" Then


When you change to Application.InputBox, you won't need the quotes around
these.

MsgBox ("Your slection must be 1, 2, 3 or 4; you have selected an

invalid key!")
ElseIf RptKey = "1" Then 'Report based on net Whse sales
Range("FLD_CHK_TOPRINT_WNS").Select


This will be the biggest time savings. Anytime you Select or Activate
anything, it takes time. You should work directly with the objects instead
of selecting them and working with the Selection object.

You should also make Application.ScreenUpdating = False at the beginning of
your sub. Hiding rows updates the screen and will slow things down.

I think making the code more efficient will be good even if it doesn't solve
the problem. If you like, you can send me the workbook and I can make some
specific recommendations for rewriting it. If you can't do that, I will use
the code that's here. It's a big job, though, so I won't be able to get it
done today.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com