Screenshot range & save to path

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning.
As per title & some info for you.
Many Thanks.

Commandbutton1 will have the code
Range to screenshot is E5:F24
Path to save screenshot is C:\Users\Ian\Desktop\SCREEN SHOTS
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try the following code, which will export the specified range to the specified folder, and save the image file as MyImage.jpg. Change the name as desired. Also, to change the file type, simply change the file extension (ie. .bmp, .gif, .jpg, or .png). So, for example, to export the image as a PNG, use MyImage.png.

VBA Code:
Option Explicit

Sub test()

    Dim errorMessage As String
  
    If Not ExportRangeToImage(Range("E5:F24"), "C:\Users\Ian\Desktop\SCREEN SHOTS\MyImage.jpg", errorMessage) Then 'change the image filename as desired
        MsgBox errorMessage, vbCritical, "Error"
        Exit Sub
    End If
  
    MsgBox "Range has been exported successfully!", vbExclamation
  
End Sub

Public Function ExportRangeToImage(ByVal rangeToExport As Range, ByVal saveAsFileName As String, ByRef errorMessage As String) As Boolean

'export range to .bmp, .gif, .jpg, or .png image file

    On Error GoTo errorHandler
  
    rangeToExport.CopyPicture appearance:=xlScreen, Format:=xlPicture
  
    With rangeToExport.Parent.ChartObjects.Add(Left:=rangeToExport.Left, Top:=rangeToExport.Top, Width:=rangeToExport.Width + 2, Height:=rangeToExport.Height + 2)
        .Activate
        With .Chart
            .ChartArea.Format.Line.Visible = msoFalse
            .Paste
            With .Pictures(1)
                .Left = .Left + 2
                .Top = .Top + 2
            End With
            .Export fileName:=saveAsFileName
        End With
        .Delete
    End With
  
    ExportRangeToImage = True
  
    Exit Function
  
errorHandler:
    errorMessage = "Error " & Err.Number & ": " & Err.Description
    ExportRangeToImage = False

End Function

Hope this helps!
 
Last edited:
Upvote 0
Solution
@Domenic
I have an issue with this project.
I am unable to type in the cells within the range.

My goal was to =type in each cell then at the end of the week i would screen screen shot the range & start again the next week.
What happens when i click in the range now is that i see a border around the outside of the range show up & i am unable to type or even fill the cell a different color.
 
Upvote 0
Well ive used it a few times today & its been fine.

It was a screensot upon the range on the sheet,not sure how but it hasnt done it since.
Thanks
 
Upvote 0

Forum statistics

Threads
1,215,131
Messages
6,123,223
Members
449,091
Latest member
jeremy_bp001

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