Skip to content
컴퓨터잡담
2011.11.25 13:03

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

조회 수 16206 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

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

파일 이름에 따라 이미지 출력

해당 시트에 코드 삽입.



Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)

Dim StrFile As String

Dim StrFile1 As String

Dim StrFile2 As String

Dim StrFile3 As String


Application.ScreenUpdating = False


On Error GoTo MM


'Column = 1은 열위치를 말함. ( 1=A열, 2=B열 ...)

If Target.Column = 1 And Target.Row > 1 And Target.Value <> "" Then


    '파일경로+이미지 위치 지정(Target.Value는 셀의 내용)

    'StrFile = ThisWorkbook.Path & "\img\" & Target.Value & ".jpg"

    StrFile1 = ThisWorkbook.Path & "\img\" & Target.Value & "1.jpg"

    StrFile2 = ThisWorkbook.Path & "\img\" & Target.Value & "2.jpg"

    StrFile3 = ThisWorkbook.Path & "\img\" & Target.Value & "3.jpg"

    

    '현재 활성화된 시트에 선택된 이미지를 삽입

    ActiveSheet.Pictures.Insert(StrFile1).Select


    '이미지 위치지정

    With Selection

        .Top = Target.Offset(0, 3).Top

        .Left = Target.Offset(0, 3).Left

        .Width = Target.Offset(0, 3).Width

        .Height = Target.Offset(0, 3).Height

    End With

    

    ActiveSheet.Pictures.Insert(StrFile2).Select


    '이미지 위치지정

    With Selection

        .Top = Target.Offset(0, 4).Top

        .Left = Target.Offset(0, 4).Left

        .Width = Target.Offset(0, 4).Width

        .Height = Target.Offset(0, 4).Height

    End With

    

    ActiveSheet.Pictures.Insert(StrFile3).Select


    '이미지 위치지정

    With Selection

        .Top = Target.Offset(0, 5).Top

        .Left = Target.Offset(0, 5).Left

        .Width = Target.Offset(0, 5).Width

        .Height = Target.Offset(0, 5).Height

    End With

        

End If


Target.Offset(0, 1).Select

Exit Sub


MM:

MsgBox "입력하신 RN단자에 해당하는 그림이 없습니다.", , "경북동부행복센터-김병화"

Target.Select

End Sub


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

?

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소