Private Sub FPPrint()
Dim t As Integer
Dim j As Integer
Dim N As Integer
Dim RstKH As ADODB.Recordset
    On Error GoTo Errorhandler    Set XSDExcel = New Excel.Application
        XSDExcel.Visible = False
        Set XSDExcel = Nothing
        XSDExcel.SheetsInNewWorkbook = 1
            Set zsbworkbook = XSDExcel.Workbooks.Open(App.Path + "\" + "sheet\xsfp.xlt")
            With XSDExcel.ActiveSheet
                '--------------------------------------填充客户资料
                Set RstKH = New Recordset
           
                    SQL = "select * from kh where khmc='" & TxtSHR.Caption & "'"
                    RstKH.Open SQL, db, 1, 3
                    
                .Range("F3").Value = RstKH.Fields(1)
                .Range("F4").Value = RstKH.Fields(2)
                .Range("F5").Value = RstKH.Fields(3)
                .Range("F6").Value = "M.B.: " & RstKH.Fields(4)
                
                RstKH.Close
                Set RstKH = Nothing
                '-----------------------------------------
                
                If Combo1.Text = "现金" Then
                    .Range("D9").Value = "GOTOVINA"
                Else
                    .Range("D9").Value = "Waiting...."
                End If
                
                .Range("C11").Value = LblFPHM.Caption
                .Range("F11").Value = DTPicker1.Value
                
                N = 12 + Grid.Rows
                'If n > 40 Then
                'End If
                j = 1
                For t = 14 To N
                        a = "A" + CStr(t)
                        .Range(a).Value = Grid.TextMatrix(j, 0)
                        b = "B" + CStr(t)
                        .Range(b).Value = Grid.TextMatrix(j, 1)
                        c = "C" + CStr(t)
                        .Range(c).Value = "KOM"
                        d = "D" + CStr(t)
                        .Range(d).Value = Grid.TextMatrix(j, 5)
                        e = "E" + CStr(t)
                        .Range(e).Value = Grid.TextMatrix(j, 6)
                        f = "F" + CStr(t)
                        .Range(f).Value = Grid.TextMatrix(j, 7)
                        g = "G" + CStr(t)
                        .Range(g).Value = "22%"
                        h = "H" + CStr(t)
                        .Range(h).Value = Grid.TextMatrix(j, 9)
                        I = "I" + CStr(t)
                        .Range(I).Value = Grid.TextMatrix(j, 10)
                    j = j + 1
                Next t
                .Range("F54").Value = lblJE.Caption
                .Range("G54").Value = "22%"
                .Range("H54").Value = lblSE.Caption
                .Range("I54").Value = lblJSHJ.Caption
            End With
  'dd = MsgBox("yes or no", vbYesNo + vbSystemModal)
  'If dd = vbNo Then Exit Sub
     XSDExcel.ActiveSheet.PageSetup.Orientation = xlPortrait       'xlLandscape
     XSDExcel.ActiveSheet.PageSetup.PaperSize = xlPaperA4
     XSDExcel.Caption = "打印预览"
     XSDExcel.ActiveWindow.SelectedSheets.PrintPreview
     XSDExcel.ActiveSheet.PrintOut
     XSDExcel.DisplayAlerts = False
     XSDExcel.Quit
     XSDExcel.DisplayAlerts = True
     Set XSDExcel = Nothing
  Exit Sub
Errorhandler:
        MsgBox Err.Description, vbOKOnly + vbCritical
    Exit Sub
谢谢谢谢谢谢谢谢谢谢谢谢