Crop a Screen Shot

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am running this, which is taking a screen shot, pasting, resizing, but I use two monitors, and it pastes both monitors screen shot on the page, and i want to crop off the right side,

VBA Code:
Application.SendKeys "({1068})", True
DoEvents
Sheets("Screen Shots").Paste

Dim shp As Shape
With ActiveSheet
    Set shp = .Shapes(.Shapes.Count)
End With
shp.Height = 600
shp.Width = 800

Dim h As Single, w As Single
h = -(600 - shp.Height)
w = -(1200 - shp.Width)

shp.LockAspectRatio = False
shp.PictureFormat.CropRight = w
shp.PictureFormat.CropBottom = h

When i run the last three lines of code, it doesn't crop anything off, it just makes the image smaller,

how can i tell excel to crop the right side off to a certain size?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
The code works when valid values are placed in these 2 lines ( instead of w and h )
VBA Code:
shp.PictureFormat.CropRight =  100
shp.PictureFormat.CropBottom = 250

Are w and h giving you valid values >=0

Test those values by inserting
VBA Code:
MsgBox "h: " & h & vbCr & "w " & w
below
VBA Code:
w = -(1200 - shp.Width)

Amend the formulas for h & w accordingly
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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