Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust the printarea into one paper

Tags:

excel

vba

I've defined a print area in one sheet and print it out. But this area is bigger that one paper, so it would be printed into 4 pages. I want to have all the contents in one page. So I've tried the code :

Sub PrintTable()    

With ActiveWorkbook.Sheets("myTable").PageSetup
    .PrintArea = "$A$1:$L$55"
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .PrintErrors = xlPrintErrorsDisplayed

End With
End Sub

But it doesn't work, I don't know which part to correct. I've used 'Record a Macro', perhaps I've deleted some important lines. So if you've some ideas please leave a note.

like image 296
Hiddenllyy Avatar asked Nov 16 '25 11:11

Hiddenllyy


1 Answers

I just tried it myself and this works:

   Application.PrintCommunication = False
   With ActiveSheet.PageSetup
       .FitToPagesWide = 1
       .FitToPagesTall = 1
   End With
   Application.PrintCommunication = True

Without setting the

 Application.PrintCommunication

to false and true, it doesn't work. Can you try this?

like image 109
Roeland Avatar answered Nov 19 '25 08:11

Roeland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!