자기계발/엑셀, VBA
-
[VBA] 텍스트파일에 쓰기, 읽기자기계발/엑셀, VBA 2022. 7. 30. 18:41
Private Function fCtrlFile() Set wb = ActiveWorkbook 'ThisWorkbook' Set sht = ActiveSheet Dim file_name As String file_name = wb.path & "\Text.txt" 'workbook.Open Filename:=workbook.path & "Text.txt 'FileOpen( 1, file_name, OpenMode.Input) Open file_name For Input As #1 Dim textline1 As String Dim textline2 As String textline2 = "가나다라" Line Input #1, textline1 '읽기 MsgBox textline1 Close #1 Open ..
-
Excel VBA - 파일입출력자기계발/엑셀, VBA 2022. 3. 4. 23:08
엑셀 외부에 있는 파일에 접근해 읽기, 쓰기 하는 작업을 정리해볼까합니다. FileSystemObject 방식 드라이브, 폴더, 파일,텍스트스트림 을 수정할 수 있도록, 액세스를 시켜주는 라이브러리입니다. 사용하는 방법은 1. VBA 스크립트 리본메뉴 > Tool > Refences에 "Microsoft Scripting Runtime"을 체크(활성화) 해주거나 2. "New FileSystemObject" 이렇게 사용가능합니다. 또한 CreateObject("Scripting.FileSystemObject") 로 코드 내에서 사용가능합니다. 파일 입출력 알고리즘 1. 파일 정보 초기화 (엑셀 파일 및 시트 정보) 2. 파일 입출력 정보 초기화 (경로 및 파일 설정) 3. 라이브러리 설정 4. 파일을 돌..