2007년 7월 6일 금요일

[visual basic] Excel 객체를 사용한 ExportToExcel Module

Public Function ExportToExcel(rs As Recordset, Optional FileName As String = "resultset.xls") As Boolean
    Dim ExcelSheet As Object
    Dim X As Excel.Worksheet
    'Dim cl As rdoColumn
    Dim col As Integer, row As Integer: col = 1: row = 1
    Dim I As Integer

    On Error GoTo Export_Err
    Screen.MousePointer = vbHourglass
    Set ExcelSheet = CreateObject("Excel.Sheet")
    Set X = ExcelSheet.Application.ActiveSheet
       
    X.cells(1, 1).Value = "just test 한글문제 해결되나?" ' cell의 내용 설정
    X.Name = "배송확인"  ' sheet의 이름 설정
   
    X.SaveAs App.Path & "\" & FileName
    X.Application.Quit
   
    Set ExcelSheet = Nothing
    Set X = Nothing
    Screen.MousePointer = vbDefault
    ExportToExcel = True
    Exit Function


Export_Err:


    ' code to display error or handle it
    Screen.MousePointer = vbDefault
    ExportToExcel = False
    Exit Function


End Function


댓글 없음:

댓글 쓰기