View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default Excel hanging up?

Excel XP, Win XP

Please read this entire message. It flows easily. I promise!

I'm helping an OP and I have a problem I can't figure out.

I have only one file with only one sheet.

I wrote 2 completely interdependent procedures.

Procedure #1 hides rows and columns as a function of a selection made by
clicking on one of several buttons in a UserForm. Works fine and takes
about 1 second.



Procedure #2 is a print procedure. A Workbook_BeforePrint macro cancels the
print command and calls Procedure #2. Procedure #2 sets the print range and
determines the number of columns to be printed (the visible columns) and
prints. This works fine also if ( a BIG IF) I leave it at that. (Code takes
about 0.5 seconds to run, then prints)

But I have additional code in Procedure #2 to set Portrait or Landscape as a
function of the number of columns to be printed. Let's call that additional
code Portrait/Landscape. And therein lays the problem. With that
Portrait/Landscape code in place, if I run Procedure #2, Procedure #2 takes
a very long time to run. But worse than that, after that, Procedure #1
takes a very, very, long time to run. Remember that the 2 procedures are
completely independent. It seems like Excel is getting into some state
(almost hung-up) if the Portrait/Landscape code runs. If I close the file
and open the file, everything is fine with Procedure #1 until I again run
Procedure #2. I have also cleaned the project with Rob Bovey's Code
Cleaner.



I have written the Portrait/Landscape code as:

If ColCount ColPerPage Then

Call SetPortrait

Else

Call SetLandscape

End If

The SetPortrait macro I have written as:

With ActiveSheet.PageSetup

.Orientation = xlLandscape

.FitToPagesWide = 1

.FitToPagesTall = False

End With

The Set Landscape macro I have written as :

With ActiveSheet.PageSetup

..Orientation = xlPortrait

..Zoom = 100

End With

I have also written those 2 macros with everything you get when you record a
macro and set Portrait and Landscape manually. Same problem.

Question: What is happening to cause this and what should I do differently?

Thanks for taking the time to read this rather lengthy dissertation. Otto