VBA to save Pic as JPG

ashani

Active Member
Joined
Mar 14, 2020
Messages
345
Office Version
  1. 365
Platform
  1. Windows
Hi experts,

I've tried several codes but nothing seem to be working. I'd like a VBA code that ask me to Select the Range, once selected than save that range as JPG on my Desktop.
Please can someone guide me on this.

Thank you
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi there

Try the below...

VBA Code:
Sub Export()
 Dim rng As Range
 Dim oWs As Worksheet
 Dim oRng As Range
 Dim oChrtO As ChartObject
 Dim lWidth As Long, lHeight As Long
  On Error Resume Next
 Set oWs = ActiveSheet
 Set oRng = Application.InputBox(Prompt:="Select a range", Type:=8)
    On Error GoTo 0
    If Not rng Is Nothing Then
        rng.Select
    End If
 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:="C:\Users\yOURuSERnAME\Desktop\Case.jpg", Filtername:="JPG"
 End With
 oChrtO.Delete
End Sub
 
Upvote 0
Glad we could assist and thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

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