excel - VBA Macro Printing loop -


[update below]

i have been trying write printing macro production sheet.

everything actual printouts work great. if use .zoom = false instead of .zoom = 50, printarea ends tiny on printout sheet. if use zoom=50, these inch wide margins left , right. suspect somehow doesn't process actual printarea line, have no clue why since other command lines seem work fine. tried strip code down pretty printarea, fittopagesxx, , got same issue.

i tried rewriting code multiple times , either error prompt or same results other code found on web.

   sub printjob()         dim ws worksheet         dim long      set ws = sheets("filtered_list")          = 2 ws.cells(rows.count, "f").end(xlup).row         if ws.cells(i, "f").value = 0 exit             sheets("print_page")                 .range("c8").value = ws.cells(i, "f").value                 worksheets("print_page").pagesetup.printarea = "$c$2:$l$60"                 worksheets("print_page").pagesetup.orientation = xlportrait                 worksheets("print_page").pagesetup.zoom = 50                 worksheets("print_page").pagesetup.fittopageswide = 1                 worksheets("print_page").pagesetup.fittopagestall = false                 worksheets("print_page").pagesetup.leftmargin = application.inchestopoints(0)                 worksheets("print_page").pagesetup.rightmargin = application.inchestopoints(0)                 worksheets("print_page").pagesetup.topmargin = application.inchestopoints(0)                 worksheets("print_page").pagesetup.bottommargin = application.inchestopoints(0)                 worksheets("print_page").pagesetup.headermargin = application.inchestopoints(0)                 worksheets("print_page").pagesetup.footermargin = application.inchestopoints(0)                 .printout             end     next end sub 

[update:] figured out problem after here after finding out sheet specific error. basically, print title fields need empty , code one:

.printtitlerows = "" .printtitlecolumns = "" 

i added few lines more used cleaned code noldor130884:

sub printjob()     dim ws worksheet     dim long      set ws = sheets("filtered_list")          = 2 ws.cells(rows.count, "f").end(xlup).row         if ws.cells(i, "f").value = 0 exit             worksheets("print_page")             .range("c8").value = ws.cells(i, "f").value                 .pagesetup                 .printarea = "$c$2:$l$60"                 .orientation = xlportrait                 .zoom = false                 .fittopageswide = 1                 .fittopagestall = false                 .leftmargin = application.inchestopoints(0)                 .rightmargin = application.inchestopoints(0)                 .topmargin = application.inchestopoints(0)                 .bottommargin = application.inchestopoints(0)                 .headermargin = application.inchestopoints(0)                 .footermargin = application.inchestopoints(0)                 .printtitlerows = ""                 .printtitlecolumns = ""                 .leftheader = ""                 .centerheader = ""                 .rightheader = ""                 .leftfooter = ""                 .centerfooter = ""                 .rightfooter = ""                 .leftmargin = application.inchestopoints(0)                 .rightmargin = application.inchestopoints(0)                 .topmargin = application.inchestopoints(0)                 .bottommargin = application.inchestopoints(0)                 .headermargin = application.inchestopoints(0)                 .footermargin = application.inchestopoints(0)                 .printheadings = false                 .centerhorizontally = true                 .centervertically = false                 .papersize = xlpaperletter                  end                 .printpreview         end     next end sub  

hope saves bit of headache.

first of all, let me correct code bit:

with worksheets("print_page")     .range("c8").value = ws.cells(i, "f").value     .pagesetup         .printarea = "$c$2:$l$60"         .orientation = xlportrait         .zoom = 50         .fittopageswide = 1         .fittopagestall = false         .leftmargin = application.inchestopoints(0)         .rightmargin = application.inchestopoints(0)         .topmargin = application.inchestopoints(0)         .bottommargin = application.inchestopoints(0)         .headermargin = application.inchestopoints(0)         .footermargin = application.inchestopoints(0)     end     .printout end 

now, please notice as microsoft says, zoom = false means "the fittopageswide , fittopagestall properties control how worksheet scaled.".

in code using zoom before 2 properties, therfore overwriting.

if understood correctly want do, please remove code:

.fittopageswide = 1 .fittopagestall = false 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -