Home > Software engineering >  Consult a great god VB 6 DataGrid1 data export EXCEL
Consult a great god VB 6 DataGrid1 data export EXCEL

Time:11-14

Statistics button then query the data points is used to derive the tip 424 request object
This code has been found from the BBS, please tell me where can I find this is problem, I am a VB small white
Private Sub Command2_Click ()
Dim I, r, c As Integer
Dim newxls As New Excel. Application 'statement Application object
Dim newbook As New Excel. The Workbook
Dim newsheet As New Excel. The Worksheet

The Set newbook=newxls. Workbooks. Add 'create work thin
Set newsheet=newbook. Worksheets (1) 'create work table
With CommonDialog1
. CancelError=False 'in the dialog box, press the cancel button is not an error
The Flags=cdlOFNHideReadOnly & amp; CdlOFNOverwritePrompt
. The Filter="Excel Files (*. XLS) | *. XLS" 'at the bottom of the dialog box "file type" drop-down quantico displays the contents of the "
. FilterIndex=1 "choose" save the type "the first value is the default value, namely" Excel Files (*. XLS) | *. XLS "
. ShowSave

'set the Excel format the content, now temporarily not
'With newsheet
'. The Cells. The Font. The Name="System"
. '. The Cells. The Font Size=12
'Name="data list
"'
'Range (Cells (1, 1), Cells (1, DataGrid1. Columns. The Count)). Select
'Selection. The HorizontalAlignment=xlCenter
'Selection. VerticalAlignment=xlCenter
'Selection. The Merge' merging center
'Cells (1, 1)="export excel file
"'End With

If the rs. RecordCount & gt; 0 Then
For I=0 To DataGrid1. 'circulation add header Columns. The Count - 1
Newsheet. Cells (2, I + 1)=DataGrid1. Columns (I). The Caption
Next
Rs. MoveFirst
EOF
Do Until the rs.R=rs. AbsolutePosition 'read you object position the current record number
For c=0 To DataGrid1. Columns. The Count - 1
DataGrid1, Col=c 'read c column data
Newsheet. Cells (r + 2, c + 1)=DataGrid1. Columns (c)
Next
Rs. MoveNext
Loop
End the If

Newsheet. SaveAs FileName:=CommonDialog1 FileName
Newbook. Close
Newxls. Quit
The Set newbook=Nothing
The Set newsheet=Nothing
The Set newxls=Nothing
Set the conn=Nothing
Set the rs=Nothing

End With
MsgBox "data export success," vbMsgBoxRight, "tip"
End Sub
  • Related