Does anyone know how I can add to this macro so that the saved JPG will open automatically after saving?
Possibly a separate query, but wondering if anyone has a method to save as a PNG (with the hope that it'd produce a higher resolution that JPGs).
Possibly a separate query, but wondering if anyone has a method to save as a PNG (with the hope that it'd produce a higher resolution that JPGs).
VBA Code:
Sub SaveAsJPGStats2021()
Dim ChO As ChartObject, ExportName As String
Dim CopyRange As Range
Dim Pic As Picture
Dim i As Long
With ActiveSheet
Set CopyRange = Worksheets("2021").Range("r1:y38")
If Not CopyRange Is Nothing Then
Application.ScreenUpdating = False
Worksheets("2021").Unprotect Password:=""
Columns("r:y").EntireColumn.Hidden = False
ExportName = Application.GetSaveAsFilename(InitialFileName:=.Range("a2") & " " & .Range("r2") & " - " & Format(Date, "d-mm-yyyy"), fileFilter:="JPEG Files (*.jpg), *.jpg")
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
Columns("r:y").EntireColumn.Hidden = True
Worksheets("2021").Protect Password:=""
Application.ScreenUpdating = True
End If
End With
End Sub