Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print preview sheet

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
411
0
16
IT
i use this:
Code:
 Private Sub Command2_Click()

    If Me.ListView1.ListItems.Count >= 1 Then

        Screen.MousePointer = vbHourglass

        Me.Text1.SetFocus

        Me.LAZIONI.Caption = "STAMPA IN CORSO..."
        DoEvents

        Set excelWB = excelApp.Workbooks.Open(FILENAME:=STRPATH1 & WBNAME)
        Set excelWS = excelWB.Worksheets(SHNAME)

        FILENAME = Me.LTXT.Caption
        FNAME = Left(FILENAME, InStrRev(FILENAME, ".") - 1)
        excelWS.RANGE("A2").Value = "CODICE PROGRESSIVO: " & FNAME
        excelWS.RANGE("A3").Value = "CLIENTE: " & NOME
        excelWS.RANGE("A4").Value = "RICERCA: " & NOME
        excelWS.RANGE("E2").Value = "DATA INTERVENTO: " & DATA
        excelWS.RANGE("E3").Value = "INDIR: " & INDIRIZZO
        excelWS.RANGE("E4").Value = "CITTA': " & COMUNE
        excelWS.RANGE("I2").Value = "OPERATORE: " & DATO
        excelWS.RANGE("I3").Value = "CAP: " & CAP
        excelWS.RANGE("I4").Value = "PROVINCIA: " & "(" & PR & ") - " & PROVINCIA

        'FILL SHEET TEMPLATE
        'Call FILL_SHEET
        'FILL SHEET TEMPLATE

        With Printer
            .PaperSize = vbPRPSA4
        End With

        excelWB.Worksheets(SHNAME).PrintOut

        excelWB.Close savechanges:=False

        Set excelWB = Nothing
        Set excelWS = Nothing

        excelApp.Quit

        Me.LAZIONI.Caption = "TUTTO OK!"
        DoEvents
        Sleep (1500)
        Me.LAZIONI.Caption = ""

        Screen.MousePointer = vbDefault

    Else

        Beep
        Me.Text1.SetFocus
        Me.LAZIONI.Caption = "SELEZIONARE PRIMA UN FILE!"
        DoEvents
        Sleep (1500)
        Me.LAZIONI.Caption = ""

        Me.Text1.SetFocus

    End If

End Sub

Before

excelWB.Worksheets(SHNAME).PrintOut

i nedd to printpreview the sheet, possible?
 
Hi bro...
have error on your suggestion line of code.... see image.

here: excelWB.Worksheets(SHNAME).PrintOut Preview:=True

error_Immagine_nda8xc.png
 
This message may be generated by the next line of the code, you switched workbook to preview mode and try to close it... So either automate printing as in your initial code or leave excel open in preview mode and let user close it.
A lot of printing customization can be set by code, without preview mode.
I doubt that it is possible to wait till user print the document. You can trap Workbook_BeforePrint event using WithEvents, AFAIK it fires in both print/print preview cases, except of cancelling printing it seems useless.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top