PrintOut prints groups of sheets instead of 1 group

We have this problem in many books where we select multiple sheets with VBA and print them using the following line, and Excel actually prints several groups of pages instead of one group of several pages.

ActiveWindow.SelectedSheets.PrintOut

Here is an example of a Sub that has this behavior:

 Private Sub imprimer(iColTypeRapport As Integer) Dim cell As range, rangeImpr As range, colonne As range Dim debute As Boolean ' True seulement si on a déjà sélectionné une feuille On Error GoTo erreur application.ScreenUpdating = False debute = False Set rangeImpr = ActiveSheet.range("impression") Set colonne = rangeImpr.Offset(0, iColTypeRapport).EntireColumn For Each cell In rangeImpr If LCase(Intersect(cell.EntireRow, colonne)) = "o" Then If Not debute Then Worksheets(cell.Value).Select debute = True Else Worksheets(cell.Value).Select False End If End If Next cell ActiveWindow.SelectedSheets.PrintOut Worksheets("TableauDeBord").Select application.ScreenUpdating = True Exit Sub erreur: Call GestionErreur(Err.Number, Err.Description, "modRequete", "ImportData") End Sub 

This is made even more obvious if we use Print2PDF or AdobePDF, as it will request several times (in this case, 3 times) for file names.

If I put a breakpoint in front of PrintOut, the sheets will be selected accordingly and I don't see anything unusual / unexpected.

Any idea?

+4
source share
1 answer

I saw it. This may be due to things like different print resolutions. If you search for “print book, you get multiple PDF files,” you will find the answers. With the PDF problem in particular, this can be resolved (in XL 2010 and, I suppose, 2007) by doing “Save As” in PDF instead.

+1
source

Source: https://habr.com/ru/post/1487123/


All Articles