Skip to content
조회 수 30518 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

엑셀파일 열지않고 내용 불러오기


방법1. ExecuteExcel4Macro 함수를 통하여 불러오는 방법.

방법2. DAO를 통합 방법.



strpath = ThisWorkbook.Path

Path = Left(strpath, InStrRev(strpath, "\") - 1)
Path = Path & "\";strFile = "파일명.xls"
strSheet = "쉬트명"
strAddress = Cells(X,Y).Address
변수 = ReadValue(Path, strFile, strSheet, strAddress)


펑션
Function ReadValue(Path, File, sht, Rng) As Variant
Dim Msg As String
Dim strTemp As String
If Trim(Right(Path, 1)) <> "\" Then Path = Path & "\"
'데이터가 있는 원본 파일이 없으면 에러를 표시 매크로를 종료.
If Dir(Path & File) = "" Then;ReadValue = "해당 파일이 없습니다"
Exit Function
End If
Msg = "'" & Path & "[" & File & "]" & sht & "'!" & Range(Rng).Range("a1").Address(, , xlR1C1);ReadValue = ExecuteExcel4Macro(Msg)
End Function

은근 쓸일이 많은 옵션



http://blog.naver.com/PostView.nhn?blogId=maxzon&logNo=70110710713


Option Explicit

Sub File_Read()


'쓰여질 변수 설정, 어떨땐 필요하나 싶다.

Dim lngCount As Long

Dim varData(1 To 2, 1 To 2) As Variant

Dim i As Long, j As Long, k As Long

Dim varArray As Variant

Dim strFileName As String, strTemp As String, strPath As String, strArg As String


'파일 불러오기(*.xls를 *.csv 등으로 변경도 가능하겠지.

    varArray = Application.GetOpenFilename("ExcelFile *.xls,*.xls", _

       Title:="집계할 엑셀 파일들을 Shift버튼을 눌러 모두 선택하십시오!", MultiSelect:=True)

       

       

    If TypeName(varArray) = "Boolean" Then Exit Sub

    lngCount = UBound(varArray)

    strTemp = varArray(1)

    strPath = Left$(strTemp, Len(strTemp) - Len(Dir(strTemp)))

    

    

    For i = 1 To lngCount '조회할 문서의 수만큼 횟수를 실행하겠다는 의미

      strFileName = Dir(varArray(i))

      

      

'j와 k는 A1:B2(A1,B1,A2,B2) 까지의 범위를 의미한다.

'즉, j는 A,b,c 등의 열을, k는 1,2,3 등의 행을 의미하는 것.

      

      For j = 1 To 2

      

        For k = 1 To 2

          strArg = "'" & strPath & "[" & strFileName & "]" & "Sheet1" & "'!" & _

            Range(Cells(j, k).Address).Address(ReferenceStyle:=xlR1C1)

            '위 빨간색부분이 Sheet1시트의 A1:B2영역을 의미하게 된다.


          varData(j, k) = Application.ExecuteExcel4Macro(strArg)

        Next k

      Next j

      Cells((i - 1) * 4 + 1, 1) = strTemp & " 의 내용"

      Range(Cells((i - 1) * 4 + 2, 1), Cells((i - 1) * 4 + 3, 2)) = varData

    Next i

End Sub



로그인 후 댓글쓰기가 가능합니다.

?

  1. 05
    Jan 2012
    07:00

    Excel Vba) 셀의 행, 열(column, row) 주소 알아내기 또는 삽입하기 더불어 제어하기

    CategoryExcel Views42974
    Read More
  2. 30
    Oct 2013
    17:04

    ahk) autohotkey 엑셀(Excel)에서 행값 증가시키기

    CategoryAutoHotKey Views37421
    Read More
  3. 05
    Jan 2012
    07:01

    Excel Vba) 현재 셀에서 한줄내림 (activecell.offset(1,0).Select)

    CategoryExcel Views31021
    Read More
  4. 23
    Oct 2011
    06:07

    eXCEL VBA)엑셀파일 열지않고 내용 불러오기

    Category컴퓨터잡담 Views30518
    Read More
  5. 21
    Dec 2011
    14:36

    Excel) 엑셀 콤보박스 대화상자 목록지정하기

    CategoryExcel Views29391
    Read More
  6. 14
    Oct 2011
    13:54

    Excel VBA) 원하는 범위 지정한 뒤 복사하여 붙여넣기

    Category컴퓨터잡담 Views29389
    Read More
  7. 16
    Jul 2012
    16:20

    [excel] GET.CELL사용법

    CategoryExcel Views26599
    Read More
  8. 24
    Oct 2011
    19:01

    Excel VBA (1): 셀 선택 및 변수 및 비활성시트 컨트롤하기

    Category컴퓨터잡담 Views25003
    Read More
  9. 17
    Sep 2012
    08:21

    현재 Excel 파일 이름을 셀에 삽입

    CategoryExcel Views24560
    Read More
  10. 12
    Feb 2010
    09:14

    excel 2007에서 공동 작업하기

    Category컴퓨터잡담 Views24173
    Read More
  11. 09
    Jun 2013
    12:13

    Excel) 엑셀에서 셀 입력시 자동 추가글 넣기

    CategoryExcel Views24062
    Read More
  12. 13
    Feb 2012
    13:33

    MS Office 2007 Excel 최근 문서 목록 삭제하기

    CategoryExcel Views22229
    Read More
  13. 17
    Oct 2011
    19:07

    Excel VBA) 자주쓰는 함수모음

    Category컴퓨터잡담 Views21677
    Read More
  14. 25
    Sep 2011
    21:34

    ExCEL VBA) 파일을 열지않고 값 읽어오기

    Category컴퓨터잡담 Views20216
    Read More
  15. 25
    Sep 2011
    23:31

    ExCEL VBA) 중복된 데이터 추출하기

    Category컴퓨터잡담 Views20197
    Read More
  16. 30
    Jun 2012
    08:14

    PDF, EXCEL 파일 변환

    CategoryExcel Views19809
    Read More
  17. 04
    Sep 2010
    09:38

    Excel에서 틀 고정 방법

    Category컴퓨터잡담 Views18628
    Read More
  18. 23
    Oct 2011
    12:59

    Excel VBA) DAO를 이용하여 엑셀문서 열지않고 데이타 가져오기

    Category컴퓨터잡담 Views18274
    Read More
  19. 23
    Oct 2011
    08:20

    Excel VBA) Delete Column Excel VBA - 칼럼 지우기

    Category컴퓨터잡담 Views16349
    Read More
  20. 25
    Nov 2011
    13:03

    Excel VBA) 파일 이름에 따라 이미지 출력

    Category컴퓨터잡담 Views16208
    Read More
Board Pagination Prev 1 2 Next
/ 2

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소