0
votes

All Could any one, help me with this issue please. I wanna to define excel VBA macro, to print several pages, each page has a different size than the others.

1st page range from cell (A1) to cell (I48) 2nd page range from cell (A50) to cell (I100) the rest of pages from cell (A105) to cell (I3000), each one of them contains 75 rows and 9 columns.

Thanks in advance.

1
Use the print function with the arguments such as size as necessary.Solar Mike

1 Answers

0
votes

Sheet2 formatSheet1 contains data. Sheet2 contains the details of page no, start row, end row , start column, end column to print

Sub Printtest()

Dim wb As Workbook

Dim ws1, ws2 As Worksheet

Set wb = ThisWorkbook

Set ws2 = wb.Worksheets("Sheet2")

Set ws1 = wb.Worksheets("Sheet1")
Dim LastRow As Long


    With ws2
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With


    For i = 2 To LastRow

    row_start = ws2.Cells(i, 2).Value

    row_end = ws2.Cells(i, 3).Value
    col_start = ws2.Cells(i, 4).Value
    col_end = ws2.Cells(i, 5).Value

    With ws1
    'ws1.Range(Cells(row_start, col_start), Cells(row_end, col_end)).PrintPreview

    ws1.Range(Cells(row_start, col_start), Cells(row_end, col_end)).PrintOut

    End With
    Next
End Sub