PDA

View Full Version : Printscreen, pasting and editing the picture : Not Working



montrealraaj
01-27-2010, 10:49 AM
Hi All,
First, I would like to thank all the contributors in the forum.
I am a newbie for VBA and I learnt a lot of tricks from the posts in this forum.
Curretly I am working on a small VBA program by which I can printscreen paste the same in word and crop the pasted picture to desired size.
I got the code working till pasting the printscreen in word.
Now editing the picture with Picture format seems to be a undoable task.
Nothing seems to work....So Somebody please help :help



Option Explicit
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_SNAPSHOT = &H2C
Sub PrintScreen()

keybd_event VK_SNAPSHOT, 6, 0, 0
End Sub

Sub PCPCR()

Call PrintScreen
Selection.PasteSpecial Placement:=wdInLine
Selection.Collapse Direction:=wdCollapseEnd
End Sub


It works till this point and when I type the following It throws an error
Compiler Error :Method or Data Member not found and .PictureFormat is selected.


Selection.InlineShapes.PictureFormat.CropRight =248


Then I tried pasting the selection as shape and added the following i/o existing PasteSpeacial Statement


Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteShape
and I get the following error.
"Runtime Error:5342
The specified DataType is unavailable"
I donno as what i am doing wrong so somebody please help me : pray2:

Thanks in advance for your time and Help.
Regards
Montrealraaj.

lucas
01-27-2010, 11:22 AM
I don't have any suggestions on this but I would ask why you are doing this?

Why not just copy the data?

montrealraaj
01-27-2010, 12:09 PM
Hi Steve,
Thanks for the immediate response.
I am automating the activity of taking screenshots and pasting it in word (for repoting Defects).
Also I normally remove crop certain parts of the screenshot (Like bottom Task bar) and resize the screenshot to fit the window.
Thats why I need it to get pasted as shape.

Regards,
Montrealraaj

lucas
01-27-2010, 12:55 PM
Montrealraaj, my limited skill where printscreen is involved won't help much here but it doesn't appear that you are getting the value into the clipboard.

Let me look at it a few minutes....

lucas
01-27-2010, 01:21 PM
It's getting copied but you aren't accessing the clipboard for some reason...

lucas
01-27-2010, 01:40 PM
it's a timing problem. Try this. It works fo me:

Sub PCPCR()
Call PrintScreen
DoEvents
Selection.PasteSpecial Placement:=wdInLine
Selection.Collapse Direction:=wdCollapseEnd
End Sub

montrealraaj
01-28-2010, 09:23 AM
Hi Steve,
It worked before till the paste. the problem I am having is doing an action like
.PictureFormat.CropRight = 248
Let me know if you know you have any ideas/Suggestions on this issue.
One advancement I got is that I came to know that I should make this selection a shape and then add .Picture.Format to it.
But when I am assinging the selection to a variable like below again I am getting DATA or MEthod not found error.

[code]
Dim Pic As Shape
Pic= Selection.InlineShapes.ConvertToShape()
With Pic.PictureFormat
.CropRight = 248
End With

[\Code]

Any Suggestions/Ideas are most welcome

Once again thanks for troubleshooting this issue with me

Regards,
Montrealraaj

TonyJollans
01-29-2010, 02:14 AM
1. You must say which InlineShape - Word isn't clever enough to realise there is only one in the Selection and, therefore, that must be it.
2. You must Set your Pic variable as it is a pointer, not a simple value

Changing your code for this gives:

Dim Pic As Shape
Set Pic = Selection.InlineShapes(1).ConvertToShape()
With Pic.PictureFormat
.CropRight = 248
End With
which may - or may not - do what you want, but should take you a step closer.