Sub Process()
    Dim conn As Object
    Dim rs As Object
    Dim cmd As Object
    Dim strSQL As String
    Dim wb As Object
    Dim ws As Object
    Dim i As Integer
    Dim MyDB As String
    Dim Portfolio As String
    Dim Begindate As Date

    Application.ScreenUpdating = False
    Rem 清除记录
    Sheets("Sheet2").Select
    Selection.AutoFilter
    Range("B6").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Rem 参数赋值
    Portfolio = Cells(1, 2)
    If Cells(1, 14) = "期初持仓" Then
        Begindate = Cells(1, 10)
    Else
        Begindate = Cells(1, 12)
    End If
    Sector = Cells(1, 5)
    Analyst = Cells(1, 8)
    
    'Sheets("Sheet4").Select
    '[e:e].Find(Begindate).Select
    'i = Selection.Row()
    'Nextdate = Cells(i + 1, 5)
    
    Sheets("Sheet1").Select
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    
    Rem 数据加载
    
    ' 数据库路径
    MyDB = "C:\Users\LIQI\Documents\portfolio.accdb"

    ' 创建Connection对象并连接数据库
    Set conn = CreateObject("ADODB.Connection")
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MyDB & ";Persist Security Info=False;"
    conn.Open

    ' 创建Command对象
    Set cmd = CreateObject("ADODB.Command")
    With cmd
        .ActiveConnection = conn
        .CommandType = 1
        .CommandText = "SELECT ID,TRADEDATE,TICKER,WEIGHT FROM Mockportfolio WHERE ID=? AND TRADEDATE = ?;"
        .Parameters.Append .CreateParameter(, 8, 1, 20, Portfolio)
        .Parameters.Append .CreateParameter(, 7, 1, , Begindate)
    End With

    ' 执行查询
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open cmd

    ' 导出数据到Excel工作表
    Set xlApp = GetObject(, "Excel.Application")
    Set wb = xlApp.ActiveWorkbook
    Set ws = wb.Sheets("Sheet1")


    ' 将查询结果写入工作表中
    ws.Range("A2").CopyFromRecordset rs

       
       ' 释放对象
    rs.Close
    Set rs = Nothing
   
    [b:b].Find("").Select
    i = Selection.Row()
   
    Range(Cells(2, 3), Cells(i - 1, 3)).Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("B5").Select
    ActiveSheet.Paste
        
  
    
    Rem 指数成分加载
  
    If InStr(1, Cells(1, 2), "300") = 1 Then
    benchmark = "CSI300"
    col = 1
    Else
    benchmark = "CSI500"
    col = 10
    End If
    Sheets("Sheet3").Select
    
    ' 创建Command对象
    Set cmd = CreateObject("ADODB.Command")
    With cmd
        .ActiveConnection = conn
        .CommandType = 1
        .CommandText = "SELECT Ticker,Weight FROM Benchmark WHERE BenchID=? AND Tradedate = ?;"
        .Parameters.Append .CreateParameter(, 8, 1, 20, benchmark)
        .Parameters.Append .CreateParameter(, 7, 1, , Begindate)
    End With

    ' 执行查询
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open cmd

    ' 导出数据到Excel工作表
    Set ws = wb.Sheets("Sheet3")
    
    ws.Cells(2, col).CopyFromRecordset rs
    
       
       ' 释放对象
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing
    
    Set rng = Range(Cells(2, col + 1), Cells(501, col + 1))
    rng.Value = rng.Value
    
    Cells(2, col).Select
    Range(Selection, Selection.End(xlDown)).Select
    
    
    Selection.Copy
    Sheets("Sheet2").Select
    Cells(i + 3, 2).Select
    'Cells(j - i + 5, 2).Select
    ActiveSheet.Paste
    Range("B5").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    ActiveSheet.Range("$B$5:$B$1005").RemoveDuplicates Columns:=1, Header:=xlNo
    
    Rem 数据呈现
    Range("$B$5:$B$1005").Find("").Select
    n = Selection.Row()
    Range("C5").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.AutoFill Destination:=Range(Cells(5, 3), Cells(n - 1, 14))
    
    Range("B3:N3").Select
    Selection.Copy
    Range("B4:N803").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    
    
    Range("B5").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add2 Key:=Range(Cells(5, 4), Cells(n - 1, 4)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add2 Key:=Range(Cells(5, 5), Cells(n - 1, 5)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add2 Key:=Range(Cells(5, 7), Cells(n - 1, 7)), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add2 Key:=Range(Cells(5, 8), Cells(n - 1, 8)), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    
    With ActiveWorkbook.Worksheets("Sheet2").Sort
        .SetRange Range(Cells(5, 2), Cells(n - 1, 14))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    Rem 分级展示
    If Sector <> "" Then
    Range("B4:n4").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$4:$n$999").AutoFilter Field:=3, Criteria1:=Sector
    ActiveSheet.Range("$B$4:$n$999").AutoFilter Field:=5, Criteria1:=Analyst
    
    ElseIf Analyst <> "" Then
    Range("B4:n4").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$4:$n$999").AutoFilter Field:=5, Criteria1:=Analyst
    
    Else
    Range("B4:n4").Select
    Selection.AutoFilter
    
    End If
    
    Cells.Select
    With Selection.Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Cells(1, 2).Select
    
    Rem 分类汇总
    Rem Sheets("Sheet2").Select
    Rem Range("B3").Select
    Rem Range(Selection, Selection.End(xlToRight)).Select
    Rem Range(Selection, Selection.End(xlDown)).Select
    Rem Range(Selection, Selection.End(xlDown)).Select
    Rem Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(12), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    
    Application.ScreenUpdating = True
    
End Sub
这是我的vab代码 在导出数据到excel工作表这一段时，执行语句Set ws = wb.Sheets("Sheet1")报错。错误号91 对象变量或With块变量未设置。能帮我看看怎么改吗