[Word] 글자에 해당하는 그림 파일 가져오기
- Study/VBA
- 2015. 9. 8. 21:00
원하는 위치의 글자를 선택하여, 글자에 해당하는 이미지 파일 가져오기.
Sub TextToImage()
'
' SamYeong.TextToImage Macro
'
'
Dim userName As String
Dim pngFileName As String
Dim jpgFileName As String
Dim gifFileName As String
Dim imgWidth As Integer
Dim centerPosition As Integer
Dim imgCount As Integer
ActiveDocument.Select
With Selection.Find
.Forward = True
.Wrap = wdFindStop
.Text = "Very truly Yours,"
.Execute
End With
Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=4
Selection.Expand (wdLine)
userName = Selection.Text
userName = Right(userName, Len(userName) - 5)
userName = Left(userNme, Len(userName) - 1)
userName = Trim(userName)
MsgBox (userName)
pngFileName = "I:\폴더\영어 파일명\" + userName + ".png"
jpgFileName = "I:\폴더\영어 파일명\" + userName + ".jpg"
gifFileName = "I:\폴더\영어 파일명\" + userName + ".gif"
If (Dir(pngFileName) > "") Then
ActiveDocument.Shapes.AddPicture fileName:=pngFileName, LinkToFile:=False, SaveWithDocument:=True, Top:=410
ElseIf (Dir(jpgFileName) > "") Then
ActiveDocument.Shapes.AddPicture fileName:=jpgFileName, LinkToFile:=False, SaveWithDocument:=True, Top:=410
ElseIf (Dir(gifFileName) > "") Then
ActiveDocument.Shapes.AddPicture fileName:=gifFileName, LinkToFile:=False, SaveWithDocument:=True, Top:=410
Else
MsgBox (pngFileName + " : 파일 없음")
Exit Sub
End If
imgCount = ActiveDocument.Shapes.Count
imgWidth = ActiveDocument.Shapes(ActiveDocument.Shapes.Count).width
ActiveDocument.Shapes(imgCount).WrapFormat.Type = wdWrapBehind
centerPosition = (ActiveDocument.PageSetup.pageWidth - ActiveDocument.Shapes(imgCount).width) / 2 - ActiveDocument.PageSetup.LeftMargin
ActiveDocument.Shapes(imgCount).Left = centerPosition
End Sub
'Study > VBA' 카테고리의 다른 글
Excel VBA 원하는 행,열 추출하여 정리하기. (0) | 2015.09.25 |
---|---|
[Word] 그림 삽입 VBA (0) | 2015.09.08 |
Excel & Word - 머리글&바닥글 삭제 (0) | 2014.11.01 |
이 글을 공유하기