나눔터  
  HOME > 나눔터 > 묻고답하기 > 엑셀
엑셀
엑셀에 대한 질문과 답변을 올려주세요. 단, 취지에 맞지 않는 글은 운영자가 삭제합니다.
 "000 님, 도와주세요", "부탁 드립니다.", "급합니다!" 등과 같이 막연한 제목을 달지 말아주세요.
[필독] 빠르고 정확한 답변을 얻는 16가지 Tip !
[필독] 저작권법 개정에 따른 이용안내

작성자:  

 빨강색 (ghkdudals)

추천:  2
파일:     사진대장 매크로.xlsm (468.5KB) 조회:  1622
제목:   사진자동삽입 추가질문
     
  * 답변하시는 분들께 도움이 되도록 자신의 환경을 아래 항목 옆에 기재해 주세요.

 - 엑셀 버전(95,97,2000,xp,2003,2007):2010

* 아래줄에 질문을 작성하세요 >>

==============[빨강색님 글에 대한 답변입니다]==============
그림파일이 많으면 시트를 계속추가하여 그림을 삽입합니다.

Sub Pictures_Insert()
     Dim wst As Worksheet
     Dim oPic As Picture
     Dim sPath As String, sFn As String
     
     Dim rPic As Range
     
     Dim iCnt As Integer
     Dim iRow As Integer, iCol As Integer
     
     Application.ScreenUpdating = False
     With Application.FileDialog(msoFileDialogFolderPicker)
         .Show
         If .SelectedItems.Count = 0 Then
             Exit Sub
         Else
             sPath = .SelectedItems(1) & Application.PathSeparator
         End If
     End With
     sFn = Dir(sPath & "*.jpg")           ' 폴더내 그림파일 : *.gif; *.jpg; *.jpeg
     
     Set wst = ActiveSheet
     wst.Pictures.Delete
     iRow = 6: iCol = 1: iCnt = 0
     Do While sFn <> ""
         If iCnt > 3 Then
            ' 현재시트의 양식을 추가하기 위함
            wst.Copy After:=Sheets(Sheets.Count)
             Set wst = ActiveSheet
             On Error Resume Next
             wst.Name = "S" & (Val(Mid(wst.Previous.Name, 2)) + 1)
             On Error GoTo 0
             wst.Pictures.Delete
             iRow = 6: iCol = 1: iCnt = 0
         End If
         
         Set oPic = wst.Pictures.Insert(sPath & sFn)
         iCnt = iCnt + 1
         
         Set rPic = wst.Cells(iRow, iCol).MergeArea
         With oPic
             .ShapeRange.LockAspectRatio = msoFalse
             .Left = rPic.Left + 4
             .Top = rPic.Top + 6
             .Width = rPic.Width + 6
             .Height = rPic.Height + 9
         End With
         
         sFn = Dir()
         If iCnt Mod 2 = 1 Then
             iCol = iCol + 3
         Else
             iRow = iRow + 2
             iCol = 1
         End If
     Loop
     
     Application.ScreenUpdating = True
 End Sub

사진자동삽입 답변정말 감사합니다. 덕분에 훨씬 수월하게 작업하고 있습니다 ㅠ 욕심이지만 사진크기도 가로9.16 세로6.88 고정으로 수정이 가능할까요 ?? 부탁드립니다 ㅠㅠ
 
[불량 게시물 신고]  
dewWith oPic
   .ShapeRange.LockAspectRatio = msoFalse
   .Left = rPic.Left + 4
   .Top = rPic.Top + 6
   .Width = 9.16 ' 가로사진 크기
   .Height = 6.88 ' 세로사진 크기
End With
12-12 (08:37)
삭제 ■신고
빨강색수정해서 해보니 잘안되지만 감사합니다. 공부해보겠습니다!12-13 (09:26)
삭제 ■신고
        
  

작성일 : 2018-12-11(16:14)
최종수정일 : 2018-12-11(16:14)