' Declare our variables
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range
Dim sTemp, sHeadline, sTitle As String
Dim i As Integer
Dim oldRec As LongoldRec = adc_card.Recordset.AbsolutePosition
' Create an instance of Word
Set oWord = CreateObject("Word.Application")
' Add a new, blank document
Set oDoc = oWord.Documents.add
oDoc.PageSetup.Orientation = wdOrientLandscapeadodc1.recordsource = "select ......"
adodc1.refresh
sTemp = adodc1.Recordset.GetString(adClipString, -1, vbTab)' Get the current document's range object
Set oRange = oDoc.Range
' Insert the data into the Word document
oRange.Text = sTemp
' Convert the text to a table and format the table
oRange.ConvertToTable vbTab, , , , 36' Show Word to the user
oWord.Visible = True
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range
Dim sTemp, sHeadline, sTitle As String
Dim i As Integer
Dim oldRec As LongoldRec = adc_card.Recordset.AbsolutePosition
' Create an instance of Word
Set oWord = CreateObject("Word.Application")
' Add a new, blank document
Set oDoc = oWord.Documents.add
oDoc.PageSetup.Orientation = wdOrientLandscapeadodc1.recordsource = "select ......"
adodc1.refresh
sTemp = adodc1.Recordset.GetString(adClipString, -1, vbTab)' Get the current document's range object
Set oRange = oDoc.Range
' Insert the data into the Word document
oRange.Text = sTemp
' Convert the text to a table and format the table
oRange.ConvertToTable vbTab, , , , 36' Show Word to the user
oWord.Visible = True
小弟愚笨,如给出具体代码,另加100分!决不失言!
Dim dc As Word.Document
Private Sub Command1_Click()
Set wd = New Word.Application
wd.Visible = True
Set dc = wd.Documents.Add
dc.Tables.Add dc.Range, ListView1.ListItems.Count, ListView1.ColumnHeaders.CountFor i = 1 To 3
dc.Tables(1).Cell(i, 1).Range.Text = ListView1.ListItems(i).Text
For j = 1 To 2
dc.Tables(1).Cell(i, j + 1).Range.Text = ListView1.ListItems(i).SubItems(j)
Next j
Next i
End SubPrivate Sub Form_Load()
With ListView1
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "item1"
.ColumnHeaders.Add , , "item2"
.ColumnHeaders.Add , , "item3"
For i = 1 To 3
.ListItems.Add
.ListItems(i).Text = "test1"
.ListItems(i).SubItems(1) = "test2"
.ListItems(i).SubItems(2) = "test3"
Next i
End With
End Sub
如果你的listview是与数据集绑定的,把数据集用GetString方法转成字符串,写入word即可。
否则,你可以把listview中数据项逐项连结成字符串,注意字段之间要加一个VBTab,记录之间要加一个VBCrlf。然后用同样方法写入word:
oRange.Text = sTemp