微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【Code】VB导出Excel

    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"

原文地址:https://www.jb51.cc/vb/257001.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐