Office中国论坛/Access中国论坛

标题: [求助]导出至EXCEL不能用了 [打印本页]

作者: cgl_13579    时间: 2004-10-26 17:52
标题: [求助]导出至EXCEL不能用了
以前用导出特定格式EXCEL的方法都没问题,隔一段时间再用时却告诉我“lvlcolumn”变量未定义,可是我这段时间都没动过这一部分,不知问题出在哪?请高手赐教
作者: wanshan    时间: 2004-10-26 18:44
不知道你用的什么方法导出至Excel,很可能是引用丢失,检查一下!
作者: cgl_13579    时间: 2004-10-27 00:54
这就是我用的导出方法:Private Sub cmdExport_Click()Dim xlApp As Excel.Application

Dim xlSheet As Excel.Worksheet

Dim xlWorkbook As Excel.Workbook

Dim acQuery As QueryDef

Dim objRST As Recordset

Dim strQueryName As StringstrQueryName = Me.lstQuerySet xlApp = CreateObject("Excel.Application")

xlApp.Visible = TrueSet xlWorkbook = xlApp.Workbooks.AddSet objRST = Application.CurrentDb.OpenRecordset(strQueryName)

   

Set xlSheet = xlWorkbook.Sheets(1)    For lvlColumn = 0 To objRST.Fields.Count - 1

      xlSheet.Cells(1, lvlColumn + 1).Value = _

      objRST.Fields(lvlColumn).Name

    Next    'Change the font to bold for the header row

    xlSheet.Range(xlSheet.Cells(1, 1), _

    xlSheet.Cells(1, objRST.Fields.Count)).Font.Bold = True    'Add a border to header row cells

    With xlSheet.Range(xlSheet.Cells(1, 1), _

    xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeLeft)

        .LineStyle = xlContinuous

        .Weight = xlThin

        .ColorIndex = xlAutomatic

    End With    With xlSheet.Range(xlSheet.Cells(1, 1), _

    xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeTop)

        .LineStyle = xlContinuous

        .Weight = xlThin

        .ColorIndex = xlAutomatic

    End With    With xlSheet.Range(xlSheet.Cells(1, 1), _

    xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeBottom)

        .LineStyle = xlContinuous

        .Weight = xlThin

        .ColorIndex = xlAutomatic

    End With    With xlSheet.Range(xlSheet.Cells(1, 1), _

    xlSheet.Cells(1, objRST.Fields.Count)).Borders(xlEdgeRight)

        .LineStyle = xlContinuous

        .Weight = xlThin

        .ColorIndex = xlAutomatic

    End With

With xlSheet

    .Range("A2").CopyFromRecordset objRST

    .Name = Left(strQueryName, 31)

End WithSet xlSheet = Nothing

Set xlWorkbook = Nothing

Set xlApp = Nothing

End Sub引用的勾也勾着,我至少在三台机器上运行过,都是同一个错误




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3