I have managed with screengrabbing and copying it into excel. Unfortunately it looks like the solution presented in the link below;
Using Excel VBA Macro To Capture + Save Screenshot of Specific Area In Same File
is not enough for me.
I want to have the image cropped to the specified region of my screen.
My code looks like this:
Sub Screengrab()
Application.SendKeys "({1068})", True
DoEvents
ActiveSheet.Paste Destination:=ActiveSheet.Range("B3")
Dim shp As Shape
Dim h As Single, w As Single
With ActiveSheet
Set shp = .Shapes(.Shapes.Count)
End With
h = -(675 - shp.Height)
w = -(705 - shp.Width)
'shp.Height = 2100
'shp.Width = 2400
shp.LockAspectRatio = False
shp.PictureFormat.CropRight = w
shp.PictureFormat.CropTop = h
'shp.PictureFormat.offset (-5)
End Sub
Here is what exactly is happening.
From the code above I am getting the image in the right place, however because it has been cropped I got the leftmost part of the screenshot, which includes the toolbar, which I don't want.
I want to have this cropped region pulled towards right, which would include the workpage instead of side bar.
If I change the code to shp.PictureFormat.CropLeft = w
i am getting somewhat an opposite part of the desktop, which is good. I could,t complain but it doesn't appear in my printing area, but far away.
I tried also to make the screenshot smaller, although it's too tricky, as the crop doesn't match to the area specified.
Is it some way to offset it properly?
I tried to duplicate the code parameters and do the crops from both sides, but it wasn't work, as the image was gone instantly:
Dim shp As Shape
Dim h As Single, w As Single ' l As Single, r As Single
With ActiveSheet
Set shp = .Shapes(.Shapes.Count)
End With
h = -(675 - shp.Height)
w = -(705 - shp.Width)
'l = -(500 - shp.Height)
'r = -(500 - shp.Width)
'shp.Height = 2100
'shp.Width = 2400
shp.LockAspectRatio = False
shp.PictureFormat.CropLeft = w
'shp.PictureFormat.CropLeft = r
shp.PictureFormat.CropBottom = h
'shp.PictureFormat.CropTop = l
End Sub
The offset option doesn't work, because is not supported here:
'shp.PictureFormat.offset (-5)
as well as:
shp.Range("B3").PasteSpecial
Is there any way to make the screenshot from the specified region and offset it into my area in the worksheet?