Hi jorrit77!
I'm glad my code was helpful.
Try clearing the clipboard each time the picture is taken and saved. That should fix the problem.
The first example clears the Clipboard after the picture has been saved and the second one clears it before the picture has been taken or saved.
Code:Option Explicit
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 KEYEVENTF_KEYUP = &H2
Private Function SaveFormPic() As Picture
Dim pic As StdPicture
Set pic = Clipboard.GetData(vbCFBitmap)
keybd_event vbKeyMenu, 0, 0, 0
keybd_event vbKeySnapshot, 0, 0, 0
DoEvents
keybd_event vbKeySnapshot, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyMenu, 0, KEYEVENTF_KEYUP, 0
DoEvents
Set SaveFormPic = Clipboard.GetData(vbCFBitmap)
Clipboard.SetData pic, vbCFBitmap
End Function
Private Sub Command1_Click()
SavePicture SaveFormPic, "C:\MyPic.jpg" 'picture location
Clipboard.Clear
End Sub
...or like this:
Code:Option Explicit
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 KEYEVENTF_KEYUP = &H2
Private Function SaveFormPic() As Picture
Clipboard.Clear
Dim pic As StdPicture
Set pic = Clipboard.GetData(vbCFBitmap)
keybd_event vbKeyMenu, 0, 0, 0
keybd_event vbKeySnapshot, 0, 0, 0
DoEvents
keybd_event vbKeySnapshot, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyMenu, 0, KEYEVENTF_KEYUP, 0
DoEvents
Set SaveFormPic = Clipboard.GetData(vbCFBitmap)
Clipboard.SetData pic, vbCFBitmap
End Function
Private Sub Command1_Click()
SavePicture SaveFormPic, "C:\MyPic.jpg" 'picture location
End Sub
One of these two samples should work.
If the problem persists please let me know so I can fix it.
-----------------------------------------------------
Best Regards,
Programmer
Enter your message below
Sign in or Join us (it's free).