Excel hanging problem

rabs

New Member
Joined
Nov 9, 2005
Messages
2
I need to set up a print area of a spreadsheet from the code. When I do this excel hangs in the Processes even after I close excel. I am using the following code:

.ActiveSheet.ResetAllPageBreaks
With .ActiveSheet.PageSetup
.PrintTitleRows = "$1:$2"
.PrintTitleColumns = "$A:$C"
End With

.ActiveSheet.PageSetup.PrintArea = _
"A1:" & ConvertColNumToLetter(GetLastCol()) & intFirstPageBrkRow - 1 & ",A" & intFirstPageBrkRow & ":" & ConvertColNumToLetter(GetLastCol() + 2) & intSecondPageBrkRow - 1 & ",A" & intSecondPageBrkRow & ":" & ConvertColNumToLetter(GetLastCol()) & "250"


Thanks to anyone who could help.

rabs
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
rabs,
Welcome to the board.

First thing is that setup is a little complex for setting a print range. I'm assuming you want to set up the print to print the entire worksheet. Here's the easiest way.
Don't set a print range, allow excel to figure it out for you. These three lines of code should take care of it for you, combined with your with statement.

.Zoom = False
.FitToPagesTall = False
.FitToPagesWide = 1

This will cause Excel to setup print settings as 1 page wide, and print the number of pages required based on the actual workbook itself.

HTH
Cal
 
Upvote 0
Cal,

Thanks for the quick response. I must do the page setup at run time as the data size changes everytime I run it. The problem is when I do the PageSetup at run time, Excel process is not killed entirely even when I close the object. Just wondering if there is a work around to this problem.

Thanks in advance.

Rabs
 
Upvote 0
Are you accessing excel from VB? or is this a vba macro?

The code I posted on the last post, will setup the printing so that excel will print correctly, I can't explain it very well in a post, but give it a try.
I think you are running into the crash because of something you are doing in the complex statement to define the print range.
If you want to print all populated cells in the worksheet, then my code will work great, without needing to define the print range.

HTH
Cal
 
Upvote 0

Forum statistics

Threads
1,206,759
Messages
6,074,773
Members
446,086
Latest member
daywi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top