Impresión de multiple hojas

roberto

New Member
Joined
Aug 28, 2002
Messages
43
:help: Me pasaron un codigo VBA para poder imprimir varias hojas al mismo tiempo, y que cada hoja empieze en la página # 1, no importando cuantos páginas tenga cada hoja, pero me marca un error y no se como arreglarlo, ojala me puedan ayudar, el código es el siguiente (Este codigo va en un formulario con la opcion de imprimir lo antes mencionado):

Public Sub PrintMultipleSheets()
frmSheetPrint.Show
End Sub


Private Sub UserForm_Initialize()
Dim tmp As Object
With drop_books
.Clear
For Each tmp In Workbooks
.AddItem tmp.Name
Next
.ListIndex = 0
End With
End Sub


Private Sub PrintButton_Click()
PrintCommon True
End Sub


Private Sub drop_books_Change()
Dim tmp As Object
With list_sheets
.Clear
For Each tmp In Workbooks(drop_books.Value).Worksheets
.AddItem tmp.Name
Next
End With
End Sub


Private Sub PrintCommon(ByVal blnPrint As Boolean)
Dim tmp As Integer, tmp2 As Integer
Dim objSheet As Object
Dim PrintSelection() As String
Dim CurrentSelection() As String

Me.Hide
With Workbooks(drop_books.Value)
'Save the current users selection list
tmp = -1
ReDim CurrentSelection(0 To Windows(drop_books.Value).SelectedSheets.Count - 1)
For Each objSheet In Windows(drop_books.Value).SelectedSheets
tmp = tmp + 1
CurrentSelection(tmp) = objSheet.Name
Next

If optPageSeparate Then
For tmp = 0 To list_sheets.ListCount - 1
If list_sheets.Selected(tmp) Then
With .Worksheets(list_sheets.List(tmp))
If blnPrint Then .Print Else .PrintPreview
End With
End If
Next
Else
ReDim PrintSelection(0 To list_sheets.ListCount - 1)
tmp2 = -1
For tmp = 0 To list_sheets.ListCount - 1
If list_sheets.Selected(tmp) Then
tmp2 = tmp2 + 1
PrintSelection(tmp2) = .Worksheets(list_sheets.List(tmp)).Name
End If
Next
ReDim Preserve PrintSelection(0 To tmp2)

With .Sheets(PrintSelection)
If blnPrint Then .Print Else .PrintPreview
End With
End If
'Reset back the original user's selection
.Sheets(CurrentSelection).Select
End With
Unload Me
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Roberto,

¿Donde (en qué línea) es que está ocurriendo su error? ¿Qué tipo de error está ocurriendo? ¿Usted utilizó esto antes y de un repente dejó de funcionar? ¿O es que usted está apenas empezando a usarlo?
 
Upvote 0
:-D Que tal Greg, gusto en saludarte...

Gracias por responder, el error que me produce es el siguiente:

"Se ha producido el error '438' en tiempo de ejecución: El objeto
no admite esta propiedad o método"


en la macro: PrintCommon
en la linea: If blnPrint Then .Print Else .PrintPreview
y apenas lo estoy usando o probando..

:help: Ojala me puedas ayudar...
 
Upvote 0
Hola Roberto,

Creo que pude arreglar su problema. Hice un UserForm con los objectos nombrados según lo que vi en el código. (La persona quien escribió eso sí hizo eso más fácil por haber seguido el "Hungarian Convention".) Logré que me funcionara. Cambié como tres cosas <ul>[*]PrintSelection es un "array" y no tuvo "subscript"[*]Creo que faltaba un aro (loop)[*]El método es .PrintOut no es .Print[/list]Si es posible recomiendo que trate de ponerse en contacto con quien escribió este programita porque realmente está bien hecho y me soprende que hayan errores así. Siempre es mejor comunicarse con el autor original cuando sea posible.

<font face=Courier New>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> PrintCommon(<SPAN style="color:#00007F">ByVal</SPAN> blnPrint <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)
    <SPAN style="color:#00007F">Dim</SPAN> tmp <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, tmp2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> objSheet <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> PrintSelection() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> CurrentSelection() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    
    Me.Hide
    <SPAN style="color:#00007F">With</SPAN> Workbooks(drop_books.Value)
    <SPAN style="color:#007F00">'Save the current users selection list</SPAN>
        tmp = -1
        <SPAN style="color:#00007F">ReDim</SPAN> CurrentSelection(0 <SPAN style="color:#00007F">To</SPAN> Windows(drop_books.Value).SelectedSheets.Count - 1)
        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> objSheet <SPAN style="color:#00007F">In</SPAN> Windows(drop_books.Value).SelectedSheets
            tmp = tmp + 1
            CurrentSelection(tmp) = objSheet.Name
        <SPAN style="color:#00007F">Next</SPAN>
        <SPAN style="color:#00007F">If</SPAN> optPageSeparate <SPAN style="color:#00007F">Then</SPAN>
            <SPAN style="color:#00007F">For</SPAN> tmp = 0 <SPAN style="color:#00007F">To</SPAN> list_sheets.ListCount - 1
                <SPAN style="color:#00007F">If</SPAN> list_sheets.Selected(tmp) <SPAN style="color:#00007F">Then</SPAN>
                    <SPAN style="color:#00007F">With</SPAN> .Worksheets(list_sheets.List(tmp))
                        <SPAN style="color:#00007F">If</SPAN> blnPrint <SPAN style="color:#00007F">Then</SPAN> .PrintOut <SPAN style="color:#00007F">Else</SPAN> .PrintPreview
                    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
                <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
            <SPAN style="color:#00007F">Next</SPAN>
        <SPAN style="color:#00007F">Else</SPAN>
            <SPAN style="color:#00007F">ReDim</SPAN> PrintSelection(0 <SPAN style="color:#00007F">To</SPAN> list_sheets.ListCount - 1)
            tmp2 = -1
            <SPAN style="color:#00007F">For</SPAN> tmp = 0 <SPAN style="color:#00007F">To</SPAN> list_sheets.ListCount - 1
                <SPAN style="color:#00007F">If</SPAN> list_sheets.Selected(tmp) <SPAN style="color:#00007F">Then</SPAN>
                    tmp2 = tmp2 + 1
                    PrintSelection(tmp2) = .Worksheets(list_sheets.List(tmp)).Name
                <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
            <SPAN style="color:#00007F">Next</SPAN>
            <SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> PrintSelection(0 <SPAN style="color:#00007F">To</SPAN> tmp2)
            <SPAN style="color:#00007F">For</SPAN> tmp = <SPAN style="color:#00007F">LBound</SPAN>(PrintSelection) <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(PrintSelection)
                <SPAN style="color:#00007F">With</SPAN> .Worksheets(PrintSelection(tmp))
                    <SPAN style="color:#00007F">If</SPAN> blnPrint <SPAN style="color:#00007F">Then</SPAN> .PrintOut <SPAN style="color:#00007F">Else</SPAN> .PrintPreview
                <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
            <SPAN style="color:#00007F">Next</SPAN> tmp
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
        <SPAN style="color:#007F00">'Reset back the original user's selection</SPAN>
        .Sheets(CurrentSelection).Select
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    Unload Me
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>


</FONT>

Atte,
 
Upvote 0
:bow: Arigato Greg...

Tomaré en cuenta los sabios consejos y gracias de nuevo, y espero que les pueda servir este grandioso código a los demás en este excelente Board, que para mi es el mejor...

:beerchug: Brindo por ello!!!!
 
Upvote 0
Saludos a todos!
Soy nuevo en el foro y veo con agrado que se dan soluciones sin
importar nuestros diferentes lenguajes, que la regla marca una muy
especial en comun... EXCEL.
Felicidades a todos.
8-)
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,565
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top