Professional Documents
Culture Documents
(VB) Insert Image To Excel
(VB) Insert Image To Excel
Dim excelApp
Set excelApp = CreateObject(Excel.Application)
excelApp.Visible = True
Dim excelWorkbook
Set excelWorkbook = excelApp.Workbooks.Open(CUsersFAS SCV01Desktoptest.xlsx, False)
' 폴더 경로 지정
Dim folderPath
folderPath = CUsersFAS SCV01Desktoptest
' FileSystemObject 생성
Dim fso
Set fso = CreateObject(Scripting.FileSystemObject)
' 폴더 내 모든 이미지 파일 처리
Dim folder
Set folder = fso.GetFolder(folderPath)
Dim imageFiles
Set imageFiles = folder.Files
Dim num
num = 1 ' 이미지가 들어갈 처음 cell 의 row 값
For each imageFile In imageFiles
Dim excelRange
Set excelRange = excelSheet.Range(B+CSTR(num)) '이미지 column 값이 B 라고 가정
Dim excelShape
Set excelShape = excelSheet.Shapes.AddPicture(imagePath, False, True,
excelRange.Left, excelRange.Top,-1 ,45)
excelShape.Name = imageName
Wscript.echo imageFile.path
num = num+1
Next
' 엑셀 파일 저장 및 닫기
excelWorkbook.Save
excelWorkbook.Close
' 객체 해제
Set excelShape = Nothing
Set excelRange = Nothing
Set excelSheet = Nothing
Set excelWorkbook = Nothing
excelApp.Quit
Set excelApp = Nothing
Set fso = Nothing