반응형
아래 코드는 엑셀 특정 범위를 그림파일로 저장하는 코드이다.
지금은 첫번째 시트에서 "a1"에 연결된 범위를 그림파일로 저장하는 코드인데 상황에 맞게 변경하면 된다.
또 그림파일 경로는 "C:\test_temp"로 경로설정을 해두었는데 이것도 상황에 맞게 변경하면 된다.
Function Export(in_str저장파일 As String) As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim wb As Workbook
Dim oWs As Worksheet
Dim oRng As Range
Dim oChrtO As ChartObject
Dim lWidth As Long, lHeight As Long
Set wb = ThisWorkbook
Set oWs = wb.Sheets(1)
Set oRng = oWs.Range("a1").CurrentRegion
oRng.CopyPicture xlScreen, xlPicture
lWidth = oRng.Width
lHeight = oRng.Height
Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
oChrtO.Activate
With oChrtO.Chart
.Paste
.Export Filename:=in_str저장파일, Filtername:="JPG"
End With
oChrtO.Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Function
Sub test()
Dim in_str저장파일 As String
in_str저장파일 = "C:\test_temp\Summary.jpg"
If Dir("C:\test_temp") = "" Then
MkDir ("C:\test_temp")
End If
Debug.Print Export(in_str저장파일)
End Sub
반응형
'[VBA]' 카테고리의 다른 글
[VBA] Dynamic Array(동적으로 배열 추가하기) (0) | 2024.04.03 |
---|---|
[VBA]엑셀 다중 콤보박스(Excel Multi Select Combo Box) (4) | 2023.12.22 |
[VBA] VBA 정규식 사용하기 (0) | 2022.08.24 |
[VBA] vba string.format, printf 기능 (0) | 2022.06.04 |
[VBA] 소수점 자릿수 계산 (0) | 2022.02.18 |