VBA Code:
Sub SaveAsJPG()
Dim ChO As ChartObject, ExportName As String
Dim CopyRange As Range
Dim Pic As Picture
Dim i As Long
Dim Fold As String
Dim Name As String
Dim Path As String
Fold = ActiveSheet.Range("R1")
Name = ActiveSheet.Range("H3").Value & " " & ActiveSheet.Range("D3").Value
Path = Fold & Application.PathSeparator & Name & ".jpg"
With ActiveSheet
Set CopyRange = Range("B1:I43")
If Not CopyRange Is Nothing Then
Application.ScreenUpdating = False
ExportName = Path
If Not ExportName = "False" Then
CopyRange.Copy
.Pictures.Paste
Set Pic = .Pictures(.Pictures.Count)
Set ChO = .ChartObjects.Add(Left:=10, Top:=10, Width:=Pic.Width, Height:=Pic.Height)
Application.CutCopyMode = False
Do
DoEvents
Pic.Copy
DoEvents
ChO.Chart.Paste
DoEvents
i = i + 1
Loop Until (ChO.Chart.Shapes.Count > 0 Or i > 50)
ChO.Chart.Export Filename:=ExportName, Filtername:="JPG"
ChO.Delete
Pic.Delete
End If
Application.ScreenUpdating = True
End If
End With
MsgBox "Payslip created for " & ActiveSheet.Range("D3") & " in " & Fold
End Sub