Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     <SOLVED Macro to automatically print out an Excel

Read-Only Read-Only Topic
Go
Search
Notify
Tools
<SOLVED Macro to automatically print out an Excel
 Login/Join
 
Guru
posted
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 Cool

This message has been edited. Last edited by: S.J. Kadish,


Sandy Kadish
Dev: 8.2.04- PostgreSQL
Test: 8.2.04 - PostgreSQL
Prod: 8.2.04 - PostgreSQL
 
Posts: 238 | Location: Atlanta, GA/Rehovot, Israel | Registered: May 06, 2003Report This Post
Expert
posted Hide Post
Lets hope that we are a prosperous nation.



Tony A is a big one for VB macros, perhaps he can help.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Master
posted Hide Post
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


Source: http://www.mrexcel.com/archive/Printing/30490.html

(or look at the Excel.PageSetup.PrintArea method)


- Print the Worksheet

Excel.WorkSheet.PrintOut

(example: ActiveSheet.PrintOut)
See Help file in Excel VBA editor for usage example.

- I'd suggest against 0" margins unless you are working with a specific printer that can handle that. Otherwise, I'd set this in the FEX.

ON TABLE SET STYLE *
     UNITS=IN,
     LEFTMARGIN=0.000000,
     RIGHTMARGIN=0.000000,
     TOPMARGIN=0.000000,
     BOTTOMMARGIN=0.000000,
     SQUEEZE=ON,
$



- "Fix the rows at the top of the page so that these rows will always appear"

This is called FreezePane and you can find details here: http://www.automateexcel.com/2...el_vba_freeze_panes/

(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.

** You will at some point run into the 'Macro Warning' *feature*. See these instructions to turn it off: http://www.mrexcel.com/archive/VBA/2432.html

Regards,
- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
 
Posts: 561 | Registered: February 03, 2010Report This Post
Guru
posted Hide Post
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

Sub PrintSetup()
'
' PrintSetup Macro
' Macro recorded 10/22/2010 by Sanford Kadish
'
'
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$20"
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = -3
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 200
.PrintErrors = xlPrintErrorsDisplayed
End With
End Sub

No guarantees but it does work over here.

Regards to the Focus Nation, Big Grin [

This message has been edited. Last edited by: S.J. Kadish,


Sandy Kadish
Dev: 8.2.04- PostgreSQL
Test: 8.2.04 - PostgreSQL
Prod: 8.2.04 - PostgreSQL
 
Posts: 238 | Location: Atlanta, GA/Rehovot, Israel | Registered: May 06, 2003Report This Post
Master
posted Hide Post
Ah, the old macro recorder trick. Good idea. I tend to try to solve problems the hard way. Hope it works as intended.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
 
Posts: 561 | Registered: February 03, 2010Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     <SOLVED Macro to automatically print out an Excel

Copyright © 1996-2020 Information Builders