• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

çift taraflı yazdırma

Katılım
26 Ocak 2008
Mesajlar
37
Excel Vers. ve Dili
2007 & 2013 TR
Arkadaşlar kullandığım bir veri tabanı var.Aynı sheets üzerinde bu veriler bazen çoğalmakta bazende azalmakta (Bazen 8 sayfa bazende en fazla 10 sayfaya çıkmakta), tabiki bu durumdada doğal olarak sayfa sayısı azalıp çoğalmaktadır.
1- aşağıdaki kod haricinde otomatik olarak iki yüze yazdırabileceğimiz bir kod varmı?
2-eğer birinci şıkkı uygulayamıyorsak, 1. sayfayı yazdırdıktan sonra 2. sayfanın boş olup olmadığını kontrol edecek (Not:GÜNDEM sayfasının 2 nci 3 ncü ve diğer sayfalarını kontrol edecek, yani ayrı bir sayfa değil) eğer boşsa GoTo 10 gidecek ve diğer sayfalar içinde

Private Sub CommandButton4_Click()
'GÜNDEMİ YAZDIR
If MsgBox("Yazıcıya 6 adet kağıt yerleştirdinizmi?", vbYesNo) = vbNo Then
MsgBox "Kağıt yerleştirmediğiniz için işlemi iptal ettiniz." & vbCrLf & "" & vbCrLf & "Güle Güle.........", vbInformation
Exit Sub
End If

ActiveSheet.PageSetup.PrintArea = "$A$1:$S$" & Range("S65536").End(xlUp).Row 'YAZDIRMA ALANI BELİRLENİR

ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1
'If sayfa boşsa Then GoTo 10
ActiveWindow.SelectedSheets.PrintOut From:=3, To:=3, Copies:=1
'If sayfa boşsa Then GoTo 10
ActiveWindow.SelectedSheets.PrintOut From:=5, To:=5, Copies:=1
'If sayfa boşsa Then GoTo 10
ActiveWindow.SelectedSheets.PrintOut From:=7, To:=7, Copies:=1
'If sayfa boşsa Then GoTo 10
ActiveWindow.SelectedSheets.PrintOut From:=9, To:=9, Copies:=1

If MsgBox("Şimdi kağıtları ters çevirin." & vbCrLf & "Çift sayfalar basılacak, yazdırılsınmı?", vbYesNo) = vbNo Then
MsgBox "Yazdırma işleminiz iptal edildi", vbInformation
Exit Sub
End If

10
ActiveWindow.SelectedSheets.PrintOut From:=2, To:=2, Copies:=1
'If sayfa boşsa Then GoTo 20
ActiveWindow.SelectedSheets.PrintOut From:=4, To:=4, Copies:=1
'If sayfa boşsa Then GoTo 20
ActiveWindow.SelectedSheets.PrintOut From:=6, To:=6, Copies:=1
'If sayfa boşsa Then GoTo 20
ActiveWindow.SelectedSheets.PrintOut From:=8, To:=8, Copies:=1
'If sayfa boşsa Then GoTo 20
ActiveWindow.SelectedSheets.PrintOut From:=10, To:=10, Copies:=1
20
Sheets("İCMAL").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1
Sheets("GÜNDEM").Select
MsgBox "Yazdırma işlemi bitti.", vbInformation
End Sub
 
Son düzenleme:
Copy/Paste dışında bu biraz zahmetli iş... :)

En alttaki "DuplexTest" isimli proseduru deneyin.

Kod:
'Written: June 17, 2010
'Author:  Leith Ross
'Summary: Sets a printer to Duplex mode or back to Simplex. There are 2 duplex settings:
'         Book style and Legal (Flip) style. See comment box below for the values.


   Public Type PRINTER_DEFAULTS
       pDatatype As Long
       pDevmode As Long
       DesiredAccess As Long
   End Type

   Type PRINTER_INFO_2
       pServerName As Long
       pPrinterName As Long
       pShareName As Long
       pPortName As Long
       pDriverName As Long
       pComment As Long
       pLocation As Long
       pDevmode As Long             ' Pointer to DEVMODE
       pSepFile As Long
       pPrintProcessor As Long
       pDatatype As Long
       pParameters As Long
       pSecurityDescriptor As Long  ' Pointer to SECURITY_DESCRIPTOR
       Attributes As Long
       Priority As Long
       DefaultPriority As Long
       StartTime As Long
       UntilTime As Long
       Status As Long
       cJobs As Long
       AveragePPM As Long
   End Type

   Type DEVMODE
       dmDeviceName As String * 32
       dmSpecVersion As Integer
       dmDriverVersion As Integer
       dmSize As Integer
       dmDriverExtra As Integer
       dmFields As Long
       dmOrientation As Integer
       dmPaperSize As Integer
       dmPaperLength As Integer
       dmPaperWidth As Integer
       dmScale As Integer
       dmCopies As Integer
       dmDefaultSource As Integer
       dmPrintQuality As Integer
       dmColor As Integer
       dmDuplex As Integer
       dmYResolution As Integer
       dmTTOption As Integer
       dmCollate As Integer
       dmFormName As String * 32
       dmUnusedPadding As Integer
       dmBitsPerPel As Integer
       dmPelsWidth As Long
       dmPelsHeight As Long
       dmDisplayFlags As Long
       dmDisplayFrequency As Long
       dmICMMethod As Long
       dmICMIntent As Long
       dmMediaType As Long
       dmDitherType As Long
       dmReserved1 As Long
       dmReserved2 As Long
   End Type

   Const DM_DUPLEX = &H1000&
   Const DM_IN_BUFFER = 8

   Const DM_OUT_BUFFER = 2
   Const PRINTER_ACCESS_ADMINISTER = &H4
   Const PRINTER_ACCESS_USE = &H8
   Const STANDARD_RIGHTS_REQUIRED = &HF0000
   Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
                               PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)

   Public Declare Function ClosePrinter _
     Lib "winspool.drv" _
       (ByVal hPrinter As Long) _
     As Long
    
   Public Declare Function DocumentProperties _
     Lib "winspool.drv" _
       Alias "DocumentPropertiesA" _
         (ByVal hWnd As Long, _
          ByVal hPrinter As Long, _
          ByVal pDeviceName As String, _
          ByVal pDevModeOutput As Long, _
          ByVal pDevModeInput As Long, _
          ByVal fMode As Long) _
     As Long
     
   Public Declare Function GetPrinter _
     Lib "winspool.drv" _
       Alias "GetPrinterA" _
         (ByVal hPrinter As Long, _
          ByVal Level As Long, _
          ByRef pPrinter As Byte, _
          ByVal cbBuf As Long, _
          ByRef pcbNeeded As Long) _
     As Long
     
   Public Declare Function OpenPrinter _
     Lib "winspool.drv" _
       Alias "OpenPrinterA" _
         (ByVal pPrinterName As String, _
          ByRef phPrinter As Long, _
          ByRef pDefault As PRINTER_DEFAULTS) _
     As Long
     
   Public Declare Function SetPrinter _
     Lib "winspool.drv" _
     Alias "SetPrinterA" _
       (ByVal hPrinter As Long, _
         ByVal Level As Long, _
         ByRef pPrinter As Byte, _
         ByVal Command As Long) _
     As Long

   Public Declare Sub CopyMemory _
     Lib "kernel32" _
       Alias "RtlMoveMemory" _
         (ByRef pDest As Any, _
          ByRef pSource As Any, _
          ByVal cbLength As Long)
 
   Public Declare Function StrLen _
     Lib "kernel32" _
       Alias "lstrlenA" _
         (ByVal lpString As Long) As Long
 
   ' ==================================================================
   ' SetPrinterToDuplex.
   '
   '  Set the Duplex flag for the specified default properties
   '  of the printer driver.
   '
   '  Returns: True on success and False on error. An error will also
   '  display a message box. These messages are displayed for information
   '  only.
   '
   '  Parameters:
   '    PrinterName - The name of the printer to be used as an ANSI string.
   '
   '    DuplexSetting - One of the following standard settings:
   '       1 = None
   '       2 = Duplex on long edge (book)
   '       3 = Duplex on short edge (legal)
   '
   ' ==================================================================
   Public Function SetPrinterToDuplex(ByVal PrinterName As String, _
                                      ByVal DuplexSetting As Long) As Boolean

      Dim hPrinter As Long
      Dim PD As PRINTER_DEFAULTS
      Dim PINFO As PRINTER_INFO_2
      Dim DM As DEVMODE
   
      Dim DevModeData() As Byte
      Dim PInfoMemory() As Byte
      Dim nBytesNeeded As Long
      Dim nRet As Long, nJunk As Long
   
      On Error GoTo cleanup
   
      If (DuplexSetting < 1) Or (DuplexSetting > 3) Then
         MsgBox "Error: dwDuplexSetting is incorrect."
         Exit Function
      End If
      
      PD.DesiredAccess = PRINTER_ALL_ACCESS
      nRet = OpenPrinter(PrinterName, hPrinter, PD)
      If (nRet = 0) Or (hPrinter = 0) Then
         If Err.LastDllError = 5 Then
            MsgBox "Access denied."
         Else
            MsgBox "Cannot open the printer specified " & _
              "(make sure the printer name is correct)."
         End If
         Exit Function
      End If
   
      nRet = DocumentProperties(0&, hPrinter, PrinterName, 0&, 0&, 0&)
      If (nRet < 0) Then
         MsgBox "Cannot get the size of the DEVMODE structure."
         GoTo cleanup
      End If
   
      ReDim DevModeData(nRet + 100) As Byte
      nRet = DocumentProperties(0&, hPrinter, PrinterName, _
                  VarPtr(DevModeData(0)), 0&, DM_OUT_BUFFER)
      If (nRet < 0) Then
         MsgBox "Cannot get the DEVMODE structure."
         GoTo cleanup
      End If
   
      Call CopyMemory(DM, DevModeData(0), Len(DM))
   
      If Not CBool(DM.dmFields And DM_DUPLEX) Then
        MsgBox "You cannot modify the duplex flag for this printer " & _
               "because it does not support duplex or the driver " & _
               "does not support setting it from the Windows API."
        GoTo cleanup
      End If
   
      DM.dmDuplex = DuplexSetting
      Call CopyMemory(DevModeData(0), DM, Len(DM))
   
      nRet = DocumentProperties(0&, hPrinter, PrinterName, _
        VarPtr(DevModeData(0)), VarPtr(DevModeData(0)), _
        DM_IN_BUFFER Or DM_OUT_BUFFER)

      If (nRet < 0) Then
        MsgBox "Unable to set duplex setting to this printer."
        GoTo cleanup
      End If
   
      Call GetPrinter(hPrinter, 2&, 0&, 0&, nBytesNeeded)
      If (nBytesNeeded = 0) Then GoTo cleanup
   
      ReDim PInfoMemory(nBytesNeeded + 100) As Byte

      nRet = GetPrinter(hPrinter, 2&, PInfoMemory(0), nBytesNeeded, nJunk)
      If (nRet = 0) Then
         MsgBox "Unable to get shared printer settings."
         GoTo cleanup
      End If
   
      Call CopyMemory(PINFO, PInfoMemory(0), Len(PINFO))
        PINFO.pDevmode = VarPtr(DevModeData(0))
        PINFO.pSecurityDescriptor = 0
      Call CopyMemory(PInfoMemory(0), PINFO, Len(PINFO))
   
      nRet = SetPrinter(hPrinter, 2&, PInfoMemory(0), 0&)
      If (nRet = 0) Then
         MsgBox "Unable to set shared printer settings."
      End If
   
      SetPrinterToDuplex = CBool(nRet)

cleanup:
      If (hPrinter <> 0) Then Call ClosePrinter(hPrinter)

End Function

Function Printer_Device_Name() As String
Dim pos As Integer

pos = 11 + InStr(1, ActivePrinter, "üzerindeki")
Printer_Device_Name = Mid$(ActivePrinter, pos, Len(ActivePrinter))
End Function

Sub DuplexTest()
'    DuplexSetting - One of the following standard settings:
'       1 = None
'       2 = Duplex on long edge (book)
'       3 = Duplex on short edge (legal)
  Dim PrinterName As String
    
    PrinterName = Printer_Device_Name
    SetPrinterToDuplex PrinterName, 2
    ActiveSheet.PrintOut
End Sub
 
Bir sonuç elde edemedim.
 
Geri
Üst