加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【Code】VB导出Excel

发布时间:2020-12-17 07:39:19 所属栏目:百科 来源:网络整理
导读:Public Sub Export(frmName As Form,FlexGridName As String) Dim xlApp As Object 'Excel.Application Dim xlBook As Object 'Excel.Workbook Dim xlSheet As Object 'Excel.Worksheet Screen.MousePointer = vbHourglass On Error GoTo Err_Proc Set xlApp
    Public Sub Export(frmName As Form,FlexGridName As String)

    Dim xlApp As Object                 'Excel.Application
    Dim xlBook As Object                'Excel.Workbook
    Dim xlSheet As Object               'Excel.Worksheet

    Screen.MousePointer = vbHourglass
    
    On Error GoTo Err_Proc
    
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)

    '向表中添加数据
    Dim intRowIndex As Integer
    Dim intColIndex As Integer
    
    With frmName.Controls(FlexGridName)  '查找控件
        '填充数据到Sheet1
        For intRowIndex = 0 To .Rows - 1
            For intColIndex = 0 To .Cols - 1
                xlSheet.Cells(intRowIndex + 1,intColIndex + 1).Value = "'" & .TextMatrix(intRowIndex,intColIndex)
            Next intColIndex
        Next intRowIndex
    End With
    
    xlApp.Visible = True
    Screen.MousePointer = vbDefault
    Exit Sub
    
Err_Proc:
    Screen.MousePointer = vbDefault
    MsgBox "请确认您的电脑已安装Excel!",vbExclamation,"提示"
End Sub

Export Me,"MSHFlexGrid1"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读