首先的是是准备工作
需要引用 Microsoft Excel 11.0 Object Library
需要添加控件Mircrosoft Hierarchical FlexGrid Control 6.0(SP4) (OLEDB)
我们来看一下代码
Private Sub cmdOut_Click() Dim xlApp As Object Dim xlBook As Object Dim xlSheet As Object On Error GoTo Err_Proc Set xlApp = CreateObject("Excel.Application") '创建一个电子表格 Set xlBook = xlApp.Workbooks.Add '新建一个工作簿文件 Set xlSheet = xlBook.Worksheets(1) '新建一个sheet表 Dim i As Long Dim j As Integer With MyFlexGrid For i = 0 To .Rows - 1 '读取所有的行 For j = 0 To .Cols - 1 '读取所有的列 xlSheet.Cells(i + 1,j + 1).Value = .TextMatrix(i,j) Next j Next i End With xlApp.Visible = True '使得excel表可见 Exit Sub Err_Proc: Screen.MousePointer = vbDefault MsgBox "请确认您的电脑已安装Excel! ",vbExclamation,"提示 " End Sub原文链接:https://www.f2er.com/vb/257695.html