I realize that this discussion is somewhat beyond the realm of the Focal Point forum but since so many people do templates for EXL2K output:
Does anybody have VBA macro code that will
1. Automatically designate a print area 2. Print only populated cells 3. Return 0” margins on all sides 4. Fix the rows at the top of the page so that these rows will always appear
I’ve been researching online using Messrs. Bing and Google but felt that the Focus Nation might be a good place to search
All the best and thanks in advance for your sage advice, Sandy This message has been edited. Last edited by: S.J. Kadish,
Tony A is a big one for VB macros, perhaps he can help.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
October 22, 2010, 08:47 AM
ABT
i have not personally done this and have not tested the below to work. However I would do the following:
Place code below (or a call to the code below) in the Workbook.open event.
-Set Print Area
Sub Set_Print_Area()
Dim x As Long, lastCell As Range
x = ActiveSheet.UsedRange.Columns.Count
Set lastCell = Cells.SpecialCells(xlCellTypeLastCell)
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
End Sub
(comment: if you're automatically printing the spreadsheet isn't a freeze pane a moot point? It will have no effect on the printed page). Perhaps you want a header instead? (will print across all pages). If so, see here: http://www.cpearson.com/excel/headfoot.htm
** My assumption is that you have some experience with VBA and/or MS Office automation with VBA. If not, this would be a good place to start: http://www.functionx.com/vbaexcel/Lesson01.htm
** I hope this helps. I'm sorry I don't myself have the time to write and test the code you request, but hopefully this will allow you to get started with some examples.
Sub SetPrintArea() Dim PrintA As Range Dim c As Long 'find the last used column in the range (Columns.Count) 'by working from the extreme right, the true last column is found, 'avoiding possible empty cells within that row c = ActiveSheet.Cells(21, Columns.Count).End(xlToLeft).Column 'this will start at A21 Set PrintA = ActiveSheet.Range(Cells(21, 1), Cells(Rows.Count, c).End(xlUp)) ' PrintA.PrintPreview End Sub