cancel
Showing results for 
Search instead for 
Did you mean: 

Excel - Print (Fit to Page) Code Stage

MatthewBelia1
Level 2
Hi All,

Has anyone ever created a code stage for Excel to fit to pages when printing (e.g fit to 1 page wide/tall)? 

Thanks!
4 REPLIES 4

dvashish
Level 2

I am also looking for this solution? Can anyone provide solution to this issue please?

 


Hi @MatthewBelia1  and @dvashish 


You can create new action, Here I  named as  Fit to page and copy" Check instance and workbook"  step from Activate worksheet action as  in the screenshot.

harishmogulluri_2-1729793854417.png

harishmogulluri_4-1729793888170.png

There are no  output parameters for this action.

In the code stage use below code. you can tweak based on your requirement

 

Dim ws As Object = GetWorksheet(handle, workbookName, worksheetName, False)
Dim sheetExists As Boolean = ws IsNot Nothing

' If the worksheet exists, apply the fit to page setup
If sheetExists Then
    ws.PageSetup.Zoom = False ' Disable Zoom to enable FitToPages
    ws.PageSetup.FitToPagesWide = 1 ' Fit to one page wide
    ws.PageSetup.FitToPagesTall = 1 ' Fit to one page tall

End If

 

 

 

 



-----------------------
If I answered your query. Please mark it as the Best Answer

Harish Mogulluri

Hi @harish.mogulluri ,

Thank you for sharing the solution.
Would it be possible to input the number of sheets in this code.
Like, I have to make the first three tabs/sheets of the excel to fit to page.

Thanks! 

Hi @dvashish 
You can loop through each worksheet and update the excel to fit to page

If you found this solution helpful, please mark it as the best answer or give it a thumbs-up

-----------------------
If I answered your query. Please mark it as the Best Answer

Harish Mogulluri