我做了一个exportoexcel模块。
1。有时使用正常。
2。有时在其它地方使用,显示错误信息:缺乏过程或变量,不是模块
3。有时,执行到 .ActiveConnection = con时显示无效或关闭
Public con As New ADODB.Connection
Public Function ExporToExcelSecurity(stropen As String)
Dim rs As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
    Screen.MousePointer = 11
    Dim xlApp As New Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Dim xlQuery As Excel.QueryTable
    With rs
        If .State = adStateOpen Then
            .Close
        End If
        .ActiveConnection = con
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .LockType = adLockReadOnly
        .Source = stropen
        .Open
    End With