VBA - Open JPG after saving

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
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).

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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
you could Shell it to your favorite jpg viewer
 
Upvote 0
This needs to be able to work on different people's computers, so not sure that will work. Any idea of how I can add a line to be able to view this jpg after saving?
 
Upvote 0
you could load the pic into an image control on the userform
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top