초보자도 쉽게! 디렉토리 엑셀 파일 특정 셀 내용 일괄 변경 방법

여러 파일의 특정 셀 내용을 일괄적으로 변경해야 하는 상황은 누구에게나 번거롭고 시간 낭비로 느껴질 수 있습니다.

초보자도 쉽게 따라 할 수 있는 엑셀 파일 특정 셀 내용 일괄 변경 샘플을 제공합니다.

 

아래 샘플 코드는 VBA 매크로 이고 해당코드 기반으로 여러가지 응용이 가능합니다.

 

Sub Button1_Click()

     Dim szFileList() As String

     Dim tarPath As String

     Dim fileExt As String

     Dim fileName As String

     Dim index As Integer

 

     Dim tmpBox As Workbook

     Dim changeStr As String

 

     fileExt = "*.xlsx" 

     changeStr = "SSUN" '변경할 문자열

     index = 0

 

     tarPath = InputBox("경로를 입력하세요") '엑셀이 있는 폴더경로

 

     fileName = Dir(tarPath & "\" & fileExt)

 

     While fileName <> ""

          index = index + 1

          ReDim Preserve szFileList(1 To index)

          szFileList(index) = fileName

          fileName = Dir()

     Wend

 

     For index = 1 To UBound(szFileList)

          'MsgBox szFileList(index)

          Workbooks.Open tarPath & "\" & szFileList(index)

          Set tmpBook = Workbooks(szFileList(index))

          tmpBook.Worksheets("Sheet1").Select '변경대상 엑셀 시트

          Cells(1, 1) = changeStr

          tmpBook.Close saveChanges:=True

     Next

End Sub