Global It Leader!!



 
 

VB VB에서 엑셀파일 읽기 & 쓰기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 1건 조회 13,003회 작성일 10-06-24 11:37

본문

VB에서 엑셀파일 읽기

--------------------------------------------------------------------------------

  Dim xl As Excel.Application
  Dim wb As Excel.Workbook
  Dim sht As Excel.Worksheet
  Set xl = CreateObject("Excel.application")
  Set wb = xl.Workbooks.Open("엑셀파일이름.xls")
  Set sht = wb.Worksheets(1)
  row = 1
  Do While 1
    If sht.Cells(row, 1) = "" Then
      Exit Do
    End If
    debug.print sht.Cells(row, 1)
    debug.print sht.Cells(row, 2)
    debug.print sht.Cells(row, 3)
    row = row + 1
  Loop
  Set xl = Nothing
  Set wb = Nothing
  Set sht = Nothing

====================================================
[VB]엑셀파일에 데이터 쓰기

--------------------------------------------------------------------------------

Private Sub 엑셀에쓰기()
    Dim objExcel As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet
    Dim idx As Integer

    Set objExcel = CreateObject("excel.application")
    objExcel.Visible = True
    Set objWorkbook = objExcel.Workbooks.Add
    objExcel.DisplayAlerts = False

    Do While objWorkbook.Worksheets.count > 1
        Set objWorksheet = objWorkbook.Worksheets.item(objWorkbook.Worksheets.count)
        objWorksheet.Delete
    Loop
    objWorkbook.Worksheets("sheet1").Activate
    Set objWorksheet = objWorkbook.ActiveSheet
    objWorksheet.name = "sheet이름"
    idx = 1
    objWorksheet.Cells(idx, 1) = "자료 정리 중..."
    

    idx = idx + 1
    '제목달기
    objWorksheet.Cells(idx, 1) = "회원번호"
    objWorksheet.Cells(idx, 2) = "계약일"
    objWorksheet.Cells(idx, 3) = "최종입금일"
    objWorksheet.Cells(idx, 4) = "매출액"
    objWorksheet.Cells(idx, 5) = "잔액"
    objWorksheet.Cells(idx, 6) = "비고"

    '칼럼포맷 설정    
    objWorksheet.Columns(4).NumberFormat = "###,###,##0"
    objWorksheet.Columns(5).NumberFormat = "###,###,##0"
    objWorksheet.rows(idx).Font.Bold = True
    objWorksheet.rows(idx).HorizontalAlignment = 3

    idx = idx + 1
    objWorksheet.Cells.ColumnWidth = 12

    '셀에 데이터 쓰기
    Do While objWorksheet.Cells(idx, 1) <> ""
        objWorksheet.Cells(1, 1) = 회원변수 & " 처리 중...."        

        '필요한 자료 얻기

          .......

        '얻은 자료 셀에 넣기
        objWorksheet.Cells(idx, 1) = 회원번호
        objWorksheet.Cells(idx, 2) = 계약일
        objWorksheet.Cells(idx, 3) = 최종입금일
        objWorksheet.Cells(idx, 4) = 매출액
        objWorksheet.Cells(idx, 5) = 잔액
        objWorksheet.Cells(idx, 6) = 비고
    Loop

    '합계 계산
    objWorksheet.Cells(idx + 1, 1) = "합계"
    objWorksheet.Cells(idx + 1, 4) = "=SUM(D3:D" & idx & ")"
    objWorksheet.Cells(idx + 1, 5) = "=SUM(E3:E" & idx & ")"
    objWorksheet.Cells(1, 1) = "작업끝."

    Set objExcel = Nothing
    Set objWorksheet = Nothing
    Set objWorkbook = Nothing

end sub
[이 게시물은 오원장님에 의해 2013-02-28 16:42:35 오피스팁에서 이동 됨]

댓글목록

zsz님의 댓글

zsz 이름으로 검색 작성일
전체 95
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
55 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6322 12-16
54 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4449 11-14
53 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8855 11-05
52 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4623 10-24
51 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7111 10-24
50 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4662 07-26
49 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4743 03-09
48 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4910 03-09
47 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10842 06-30
46 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6707 06-25
45 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7468 06-25
44 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8032 06-25
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13004 06-24
42 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8538 06-24
41 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9230 06-17
40 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 24953 07-22
39 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9921 07-21
38 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8410 07-21
37 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8724 07-21
36 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8112 07-20