以下是引用PDJ72在2006-8-24 13:05:11的发言: 顶一下,版主帮忙啊 把表格做好一点,做成数据库形式的表格,适当修改以下代码即可。 Sub PrinttoWord() Dim wdApp As New Word.Application, wdDoc As Word.Document, wdTable As Word.Table Dim wdPar As Word.Range, myRange As Range, PrintCount As Integer If ActiveCell.Column = 1 And ActiveCell.Row > 1 Then wdApp.Visible = True Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\汇款证明单.doc") Set wdTable = wdDoc.Tables(1) Set wdPar = wdDoc.Paragraphs(2).Range wdPar.SetRange wdPar.Start, wdPar.End - 1 For Each myRange In Selection.Cells With myRange If Not .Comment Is Nothing Then PrintCount = CInt(VBA.Replace(.Comment.Text, .Comment.Author & ":", "")) If MsgBox(.Offset(, 3).Value & "ÒÑ´òÓ¡" & PrintCount & "次,是否继续打印该记录?", vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then GoTo GN .Comment.Text Text:=Application.UserName & ":" & Chr(10) & PrintCount + 1 Else .AddComment Application.UserName & ":" & Chr(10) & "1" End If wdPar.Text = " " & .Offset(, 8).Value & " 合同编号:" & .Value & " " End With With wdTable .Cell(1, 2).Range.Text = myRange.Offset(, 1).Value .Cell(1, 4).Range.Text = myRange.Offset(, 3).Value .Cell(1, 6).Range.Text = myRange.Offset(, 13).Value .Cell(1, 8).Range.Text = myRange.Offset(, 14).Value .Cell(2, 2).Range.Text = myRange.Offset(, 15).Value .Cell(2, 4).Range.Text = myRange.Offset(, 5).Value .Cell(3, 2).Range.Text = myRange.Offset(, 4).Value End With wdDoc.PrintOut GN: Next End If wdDoc.Close False wdApp.Quit Set wdApp = Nothing End Sub |