|
楼主 |
发表于 2005-4-23 13:11
|
显示全部楼层
刚发的程序比较难看,重发
Private Sub CB_PRINT_Click()
Dim A As Byte
Dim B As Byte
Dim i As Integer
Dim J As Integer
Dim iData() As Variant
Dim iBinno As Variant
Dim MyData As Boolean
Dim iStore As Integer
Dim iBinno1 As String
Dim MyWord As New Word.Application
Dim MyDoc As New Word.Document
Application.ScreenUpdating = False
If cb_mode.Value > 2 Then
ReDim iData(ListBox1.ListCount, 3) As Variant
J = 0
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
J = J + 1
iData(J, 1) = CStr(.List(i, 1))
iData(J, 2) = Val(.List(i, 7))
iData(J, 3) = Val(.List(i, 9))
End If
Next
End With
Else
ReDim iData(1, 3) As Variant
J = CB_RR.ListIndex
iData(1, 1) = CB_RR.List(J, 0)
iData(1, 2) = Val(CB_RR.List(J, 1))
iData(1, 3) = Val(CB_RR.List(J, 2))
J = 1
End If
Form_Print.Hide
If J > 0 Then
MyWord.Documents.Open "d:\cost\收货单.doc", Passworddocument:="COST"
Set MyDoc = MyWord.Documents("收货单")
Cnn.Open Driver_Cost
For B = 1 To J
If MsgBox("确定打印" & iData(B, 1) & "收货单请按"yes"", vbYesNo) = vbYes Then
With MyDoc.Tables(1)
.Cell(3, 2).Range.Delete
.Cell(3, 4).Range.Delete
.Cell(3, 6).Range.Delete
.Cell(2, 5).Range.Delete
.Cell(16, 6).Range.Delete
For i = 6 To 15
For A = 1 To 6
.Cell(i, A).Range.Delete
Next
Next
End With
For A = 1 To 2
CC.Cmd_Val = Array(Array(4, IIf(A = 1, "find_rr_base", "find_rr"), 2, 1), _
Array("irrno", 200, 10, iData(B, 1)), _
Array("iFrom", 16, 0, 2))
With Rs
If .EOF = False Then
If A = 1 Then
With MyDoc.Tables(1)
.Cell(3, 2).Range.InsertAfter Rs!RR_PRNO
.Cell(3, 4).Range.InsertAfter Rs!SUP_NAME
.Cell(3, 6).Range.InsertAfter Rs!DE_NAME
.Cell(2, 5).Range.InsertAfter Rs!RR_Date
.Cell(16, 6).Range.InsertAfter Format(Rs!AMOUNT, "#0.00")
End With
Else
i = 6
Do While .EOF = False
With MyDoc.Tables(1)
.Cell(i, 1).Range.InsertAfter Rs!RR_BINNO
.Cell(i, 2).Range.InsertAfter Rs!ST_NAME & IIf(Len(Rs!ST_SIZE) >0, "/" & Rs!ST_SIZE, "") & IIf(Len(Rs!ST_MAKE) > 0, "/"& Rs!ST_MAKE, "")
.Cell(i, 3).Range.InsertAfter Rs!ST_UNIT
.Cell(i, 4).Range.InsertAfter Format(Rs!RR_QTY, "#0.00")
.Cell(i, 5).Range.InsertAfter Format(Rs!RR_COST, "#0.000")
.Cell(i, 6).Range.InsertAfter Format(Rs!AMOUNT, "#0.00")
End With
i = i + 1
.MoveNext
Loop
'Cells(21, 3) = fun.DONG1(Cells(21, 7))
MyDoc.PrintOut Range:=wdPrintCurrentPage
End If
Else
A = 3
End If
.Close
End With
Next
End If
Next
Set Rs = Nothing
Cnn.Close
Set Cnn = Nothing
MyDoc.Close SaveChanges:=wdDoNotSaveChanges
MyWord.Quit
Set MyDoc = Nothing
Set MyWord = Nothing
ThisWorkbook.Activate
End If
End Sub |
|