It takes me a long time to find the program on the Internet. I just wrote the program and added comments to it, hoping to help you.
Reference before writing a program
Microsoft excel 11.0 object Library
The article I see is 10.0. Here I am office2003 and 11.0. As long as excel is installed, there will be this reference ~
Private Sub cmdsave_Click ()
MsgBox "file saved as: D: electrical network distribution circuit Management Information System Information Query Result Accident Information Query Result .xls"
Dim I As Integer
Dim j As Integer
Dim ex As Object
Dim exwbook As Object
Dim exsheet As Object
Set ex = CreateObject ("Excel. Application ")
Set exwbook = Nothing
Set exsheet = Nothing
Set exwbook = ex. Workbooks (). Add
Set exsheet = exwbook. Worksheets ("sheet1 ")
'Table header in excel. This is the header added according to my needs.
Ex. Range ("c3"). Value = "date"
Ex. Range ("d3"). Value = "time"
Ex. Range ("e3"). Value = "Site"
Ex. Range ("f3"). Value = "Reporter"