code to create multiple screen-selection prints

palaeontology

Active Member
Joined
May 12, 2017
Messages
444
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I have a sheet called 'Year 8'. In that sheet I have ....
* 25 student names in the range B6:B107 ... each student has 4 rows allocated to them, example, student A has data from C6:AV9
* student results from C6:AV107
* Column Headings in the range B5:AV5

I'd like to have a single button, that when pressed, takes 25 screen shots .... each shot would have the individual student's 4 rows visible directly underneath the row 5 column headings.

I also have a sheet called 'Year 8 Screen Shots'. In that sheet I have ...
* the same 25 student names as those found in the 'Year 8' sheet. These names are found in the range B2:B26
* the 25 student email addresses in the range C2:C26

I'd like the 25 screen shots (taken from the press of the button in the 'Year 8' sheet) to be sent to the corresponding cells in column C of the sheet called 'Year 8 Screen Shots'

Is this possible ?

Kind regards,

Chris
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
.
These will get you started :

To save range as GIF :

Code:
Option Explicit


Sub Save_Range_As_GIF()
    Dim MyChart As Chart
    Dim objPict As Object
    Dim RgCopy As Range
    
    Range("B2:G24").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
    ActiveSheet.PasteSpecial Format:="Bitmap"
    Set objPict = Selection
        
    objPict.CopyPicture 1, 1
    Set MyChart = ActiveSheet.ChartObjects.Add(1, 1, objPict.Width + 10, objPict.Height + 10).Chart
    
    With MyChart
        .Paste
        .Export ThisWorkbook.Path & Application.PathSeparator & "Temp.gif"
        .Parent.Delete
    End With
    
    MsgBox ThisWorkbook.Path & Application.PathSeparator & "Temp.gif" & " is created !"
    
    objPict.Delete
    Set objPict = Nothing
End Sub


To save range as JPG :

Code:
Option Explicit


Sub Example1()
Dim i As Integer
Dim intCount As Integer
Dim objPic As Shape
Dim objChart As Chart


'copy the range as an image
Call Sheet1.Range("A1:E12").CopyPicture(xlScreen, xlPicture)


    'remove all previous shapes in sheet2
    intCount = Sheet2.Shapes.Count
        For i = 1 To intCount
            Sheet2.Shapes.Item(1).Delete
        Next i
    'create an empty chart in sheet2
    Sheet2.Shapes.AddChart
    'activate sheet2
    Sheet2.Activate
    'select the shape in sheet2
    Sheet2.Shapes.Item(1).Select
    Set objChart = ActiveChart
    'paste the range into the chart
    objChart.Paste
    'save the chart as a JPEG
    objChart.Export ("C:\Users\My\Desktop\TestImage.Jpeg")
    
End Sub
 
Upvote 0
Hi Logit, thankyou so much for starting me with this code, I'll certainly be able to massage it from here.

One question .... the chart that the image is currently being pasted into seems to be a default width of 12.7cm and a height of 7.62cm, however, I'd like the chart to always be 46cm wide and 4cm high.

Is this possible ?

Kind regards,

Chris
 
Upvote 0
.
The code is copying this range : Range("B2:G24").CopyPicture Appearance:=xlScreen, Format:=xlBitmap




Then the code is "padding" a boundary around the copied range with this :


objPict.CopyPicture 1, 1
Set MyChart = ActiveSheet.ChartObjects.Add(1, 1, objPict.Width + 10, objPict.Height + 10).Chart


If the range you are copying in your project is exceeds your desired size, then you would need to use other code
to resize image that will be pasted.

Here is a thread that might get you going in that direction : https://www.mrexcel.com/forum/excel-questions/467651-resizing-picture-excel-using-vba.html
I did a search for "vba resize copied image".
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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